...

Text file src/cuelang.org/go/cue/testdata/eval/issue2146.txtar

Documentation: cuelang.org/go/cue/testdata/eval

     1// Issue #2146
     2//
     3// Ensure that let expressions are uniqued not only per Environment, but also
     4// per arc. This is relevant for disjunctions. Without it, an incorrect
     5// result may be cached for an arbitrary Environment.
     6-- in.cue --
     7p1: {
     8	#A: {
     9		x?: int
    10		y?: int
    11
    12		let list = [x, y]
    13		all:  [for v in list if v != _|_ {v}]
    14
    15		*{
    16			x?: _|_
    17			y:  1
    18		} | _
    19	}
    20
    21	a: #A & { x: 3 }
    22	b: #A & a
    23}
    24p2: {
    25	#A: {
    26		x?: int
    27		y?: int
    28
    29		let list = [x, y]
    30		all:  [for v in list if v != _|_ {v}]
    31
    32		_ | *{
    33			x?: _|_
    34			y:  1
    35		}
    36	}
    37
    38	a: #A & { x: 3, y: 2 }
    39	b: #A & a
    40}
    41
    42-- out/eval/stats --
    43Leaks:  18
    44Freed:  171
    45Reused: 163
    46Allocs: 26
    47Retain: 18
    48
    49Unifications: 173
    50Conjuncts:    557
    51Disjuncts:    189
    52-- out/eval --
    53(struct){
    54  p1: (struct){
    55    #A: (#struct){ |(*(#struct){
    56        x?: (_|_){
    57          // [user] explicit error (_|_ literal) in source:
    58          //     ./in.cue:10:8
    59        }
    60        y: (int){ 1 }
    61        let list#1 = (#list){
    62          0: (_|_){
    63            // [incomplete] p1.#A.list.0: cannot reference optional field: x:
    64            //     ./in.cue:6:15
    65          }
    66          1: (int){ 1 }
    67        }
    68        all: (#list){
    69          0: (int){ 1 }
    70        }
    71      }, (#struct){
    72        x?: (int){ int }
    73        y?: (int){ int }
    74        let list#1 = (#list){
    75          0: (_|_){
    76            // [incomplete] p1.#A.list.0: cannot reference optional field: x:
    77            //     ./in.cue:6:15
    78          }
    79          1: (_|_){
    80            // [incomplete] p1.#A.list.1: cannot reference optional field: y:
    81            //     ./in.cue:6:18
    82          }
    83        }
    84        all: (#list){
    85        }
    86      }) }
    87    a: (#struct){
    88      x: (int){ 3 }
    89      y?: (int){ int }
    90      let list#1 = (#list){
    91        0: (int){ 3 }
    92        1: (_|_){
    93          // [incomplete] p1.a.list.1: cannot reference optional field: y:
    94          //     ./in.cue:6:18
    95        }
    96      }
    97      all: (#list){
    98        0: (int){ 3 }
    99      }
   100    }
   101    b: (#struct){
   102      x: (int){ 3 }
   103      y?: (int){ int }
   104      let list#1multi = [
   105        〈1;x〉,
   106        〈1;y〉,
   107      ]
   108      all: (#list){
   109        0: (int){ 3 }
   110      }
   111    }
   112  }
   113  p2: (struct){
   114    #A: (#struct){ |(*(#struct){
   115        x?: (_|_){
   116          // [user] explicit error (_|_ literal) in source:
   117          //     ./in.cue:27:8
   118        }
   119        y: (int){ 1 }
   120        let list#2 = (#list){
   121          0: (_|_){
   122            // [incomplete] p2.#A.list.0: cannot reference optional field: x:
   123            //     ./in.cue:23:15
   124          }
   125          1: (int){ 1 }
   126        }
   127        all: (#list){
   128          0: (int){ 1 }
   129        }
   130      }, (#struct){
   131        x?: (int){ int }
   132        y?: (int){ int }
   133        let list#2 = (#list){
   134          0: (_|_){
   135            // [incomplete] p2.#A.list.0: cannot reference optional field: x:
   136            //     ./in.cue:23:15
   137          }
   138          1: (_|_){
   139            // [incomplete] p2.#A.list.1: cannot reference optional field: y:
   140            //     ./in.cue:23:18
   141          }
   142        }
   143        all: (#list){
   144        }
   145      }) }
   146    a: (#struct){
   147      x: (int){ 3 }
   148      y: (int){ 2 }
   149      let list#2 = (#list){
   150        0: (int){ 3 }
   151        1: (int){ 2 }
   152      }
   153      all: (#list){
   154        0: (int){ 3 }
   155        1: (int){ 2 }
   156      }
   157    }
   158    b: (#struct){
   159      x: (int){ 3 }
   160      y: (int){ 2 }
   161      let list#2multi = [
   162        〈1;x〉,
   163        〈1;y〉,
   164      ]
   165      all: (#list){
   166        0: (int){ 3 }
   167        1: (int){ 2 }
   168      }
   169    }
   170  }
   171}
   172-- out/compile --
   173--- in.cue
   174{
   175  p1: {
   176    #A: {
   177      x?: int
   178      y?: int
   179      let list#1 = [
   180        〈1;x〉,
   181        〈1;y〉,
   182      ]
   183      all: [
   184        for _, v in 〈1;let list#1〉 if (〈0;v〉 != _|_(explicit error (_|_ literal) in source)) {
   185          〈1;v〉
   186        },
   187      ]
   188      (*{
   189        x?: _|_(explicit error (_|_ literal) in source)
   190        y: 1
   191      }|_)
   192    }
   193    a: (〈0;#A〉 & {
   194      x: 3
   195    })
   196    b: (〈0;#A〉 & 〈0;a〉)
   197  }
   198  p2: {
   199    #A: {
   200      x?: int
   201      y?: int
   202      let list#2 = [
   203        〈1;x〉,
   204        〈1;y〉,
   205      ]
   206      all: [
   207        for _, v in 〈1;let list#2〉 if (〈0;v〉 != _|_(explicit error (_|_ literal) in source)) {
   208          〈1;v〉
   209        },
   210      ]
   211      (_|*{
   212        x?: _|_(explicit error (_|_ literal) in source)
   213        y: 1
   214      })
   215    }
   216    a: (〈0;#A〉 & {
   217      x: 3
   218      y: 2
   219    })
   220    b: (〈0;#A〉 & 〈0;a〉)
   221  }
   222}

View as plain text