cuelang.org/go@v0.10.1/cue/testdata/comprehensions/iferror.txtar (about)

     1  -- in.cue --
     2  a: {b: 2, c: int}
     3  
     4  wrongConcreteType: {
     5  	if a.b {
     6  		2
     7  	}
     8  }
     9  
    10  wrongType: {
    11  	if a.c {
    12  		2
    13  	}
    14  }
    15  
    16  incomplete: {
    17  	if a.d {
    18  		2
    19  	}
    20  }
    21  
    22  incomplete: {
    23  	list: [1, 2, 3]
    24  	for x in list if a.d {
    25  		x
    26  	}
    27  }
    28  
    29  // Issue #809
    30  useDefault: {
    31  	a: {
    32  		x: *"foo" | string
    33  		if x != _|_ {
    34  			y: x
    35  		}
    36  	}
    37  
    38  	issue809: {
    39  		#A: {
    40  			a: string
    41  			b: *a | string
    42  		}
    43  
    44  		s: [Name=string]: #A & {a: Name}
    45  		s: bar:           _
    46  
    47  		foo: [
    48  			for _, a in s if a.b != _|_ {a},
    49  		]
    50  	}
    51  }
    52  
    53  issue1972: {
    54  	err1: {
    55  		#patchs: []
    56  		#patchs
    57  
    58  		#someCondition: _
    59  		if #someCondition {
    60  		}
    61  	}
    62  	err1: {
    63  		someCondition: _
    64  		patchs: [...{}]
    65  		patchs
    66  		if someCondition {
    67  			patchs: _
    68  		}
    69  	}
    70  }
    71  -- out/compile --
    72  --- in.cue
    73  {
    74    a: {
    75      b: 2
    76      c: int
    77    }
    78    wrongConcreteType: {
    79      if 〈1;a〉.b {
    80        2
    81      }
    82    }
    83    wrongType: {
    84      if 〈1;a〉.c {
    85        2
    86      }
    87    }
    88    incomplete: {
    89      if 〈1;a〉.d {
    90        2
    91      }
    92    }
    93    incomplete: {
    94      list: [
    95        1,
    96        2,
    97        3,
    98      ]
    99      for _, x in 〈0;list〉 if 〈2;a〉.d {
   100        〈1;x〉
   101      }
   102    }
   103    useDefault: {
   104      a: {
   105        x: (*"foo"|string)
   106        if (〈0;x〉 != _|_(explicit error (_|_ literal) in source)) {
   107          y: 〈1;x〉
   108        }
   109      }
   110      issue809: {
   111        #A: {
   112          a: string
   113          b: (*〈0;a〉|string)
   114        }
   115        s: {
   116          [string]: (〈1;#A〉 & {
   117            a: 〈1;-〉
   118          })
   119        }
   120        s: {
   121          bar: _
   122        }
   123        foo: [
   124          for _, a in 〈1;s〉 if (〈0;a〉.b != _|_(explicit error (_|_ literal) in source)) {
   125            〈1;a〉
   126          },
   127        ]
   128      }
   129    }
   130    issue1972: {
   131      err1: {
   132        #patchs: []
   133        〈0;#patchs〉
   134        #someCondition: _
   135        if 〈0;#someCondition〉 {}
   136      }
   137      err1: {
   138        someCondition: _
   139        patchs: [
   140          ...{},
   141        ]
   142        〈0;patchs〉
   143        if 〈0;someCondition〉 {
   144          patchs: _
   145        }
   146      }
   147    }
   148  }
   149  -- out/eval/stats --
   150  Leaks:  0
   151  Freed:  43
   152  Reused: 35
   153  Allocs: 8
   154  Retain: 14
   155  
   156  Unifications: 33
   157  Conjuncts:    66
   158  Disjuncts:    57
   159  -- out/evalalpha --
   160  Errors:
   161  issue1972.err1: conflicting values [...{}] and {someCondition:_,patchs:[...{}],patchs,if someCondition {patchs:_}} (mismatched types list and struct):
   162      ./in.cue:61:8
   163      ./in.cue:63:11
   164  issue1972.err1.someCondition: field not allowed:
   165      ./in.cue:62:3
   166  wrongConcreteType: cannot use 2 (type int) as type bool:
   167      ./in.cue:4:2
   168      ./in.cue:1:8
   169  wrongType: cannot use int (type int) as type bool:
   170      ./in.cue:10:2
   171      ./in.cue:1:14
   172  
   173  Result:
   174  (_|_){
   175    // [eval]
   176    a: (struct){
   177      b: (int){ 2 }
   178      c: (int){ int }
   179    }
   180    wrongConcreteType: (_|_){
   181      // [eval] wrongConcreteType: cannot use 2 (type int) as type bool:
   182      //     ./in.cue:4:2
   183      //     ./in.cue:1:8
   184    }
   185    wrongType: (_|_){
   186      // [eval] wrongType: cannot use int (type int) as type bool:
   187      //     ./in.cue:10:2
   188      //     ./in.cue:1:14
   189    }
   190    incomplete: (_|_){
   191      // [incomplete] incomplete: undefined field: d:
   192      //     ./in.cue:16:7
   193      list: (#list){
   194        0: (int){ 1 }
   195        1: (int){ 2 }
   196        2: (int){ 3 }
   197      }
   198    }
   199    useDefault: (struct){
   200      a: (struct){
   201        x: (string){ |(*(string){ "foo" }, (string){ string }) }
   202        y: (string){ |(*(string){ "foo" }, (string){ string }) }
   203      }
   204      issue809: (struct){
   205        #A: (#struct){
   206          a: (string){ string }
   207          b: (string){ string }
   208        }
   209        s: (struct){
   210          bar: (#struct){
   211            a: (string){ "bar" }
   212            b: (string){ |(*(string){ "bar" }, (string){ string }) }
   213          }
   214        }
   215        foo: (#list){
   216          0: (#struct){
   217            a: (string){ "bar" }
   218            b: (string){ |(*(string){ "bar" }, (string){ string }) }
   219          }
   220        }
   221      }
   222    }
   223    issue1972: (_|_){
   224      // [eval]
   225      err1: (_|_){
   226        // [eval] issue1972.err1: conflicting values [...{}] and {someCondition:_,patchs:[...{}],patchs,if someCondition {patchs:_}} (mismatched types list and struct):
   227        //     ./in.cue:61:8
   228        //     ./in.cue:63:11
   229        // issue1972.err1.someCondition: field not allowed:
   230        //     ./in.cue:62:3
   231        #patchs: (#list){
   232        }
   233        #someCondition: (_){ _ }
   234        someCondition: (_|_){
   235          // [eval] issue1972.err1.someCondition: field not allowed:
   236          //     ./in.cue:62:3
   237        }
   238        patchs: (_|_){
   239          // [eval] issue1972.err1.patchs: field not allowed:
   240          //     ./in.cue:63:3
   241          //     ./in.cue:66:4
   242        }
   243      }
   244    }
   245  }
   246  -- diff/-out/evalalpha<==>+out/eval --
   247  diff old new
   248  --- old
   249  +++ new
   250  @@ -1,7 +1,9 @@
   251   Errors:
   252  -issue1972.err1: conflicting values [] and {someCondition:_,patchs:[...{}],patchs,if someCondition {patchs:_}} (mismatched types list and struct):
   253  -    ./in.cue:54:12
   254  +issue1972.err1: conflicting values [...{}] and {someCondition:_,patchs:[...{}],patchs,if someCondition {patchs:_}} (mismatched types list and struct):
   255       ./in.cue:61:8
   256  +    ./in.cue:63:11
   257  +issue1972.err1.someCondition: field not allowed:
   258  +    ./in.cue:62:3
   259   wrongConcreteType: cannot use 2 (type int) as type bool:
   260       ./in.cue:4:2
   261       ./in.cue:1:8
   262  @@ -8,8 +10,6 @@
   263   wrongType: cannot use int (type int) as type bool:
   264       ./in.cue:10:2
   265       ./in.cue:1:14
   266  -issue1972.err1: invalid list index someCondition (type string):
   267  -    ./in.cue:65:6
   268   
   269   Result:
   270   (_|_){
   271  @@ -31,8 +31,6 @@
   272     incomplete: (_|_){
   273       // [incomplete] incomplete: undefined field: d:
   274       //     ./in.cue:16:7
   275  -    // incomplete: undefined field: d:
   276  -    //     ./in.cue:23:21
   277       list: (#list){
   278         0: (int){ 1 }
   279         1: (int){ 2 }
   280  @@ -66,17 +64,23 @@
   281     issue1972: (_|_){
   282       // [eval]
   283       err1: (_|_){
   284  -      // [eval] issue1972.err1: conflicting values [] and {someCondition:_,patchs:[...{}],patchs,if someCondition {patchs:_}} (mismatched types list and struct):
   285  -      //     ./in.cue:54:12
   286  +      // [eval] issue1972.err1: conflicting values [...{}] and {someCondition:_,patchs:[...{}],patchs,if someCondition {patchs:_}} (mismatched types list and struct):
   287         //     ./in.cue:61:8
   288  -      // issue1972.err1: invalid list index someCondition (type string):
   289  -      //     ./in.cue:65:6
   290  +      //     ./in.cue:63:11
   291  +      // issue1972.err1.someCondition: field not allowed:
   292  +      //     ./in.cue:62:3
   293         #patchs: (#list){
   294         }
   295  -      someCondition: (_){ _ }
   296  -      patchs: (list){
   297  -      }
   298         #someCondition: (_){ _ }
   299  +      someCondition: (_|_){
   300  +        // [eval] issue1972.err1.someCondition: field not allowed:
   301  +        //     ./in.cue:62:3
   302  +      }
   303  +      patchs: (_|_){
   304  +        // [eval] issue1972.err1.patchs: field not allowed:
   305  +        //     ./in.cue:63:3
   306  +        //     ./in.cue:66:4
   307  +      }
   308       }
   309     }
   310   }
   311  -- diff/todo/p2 --
   312  issue1972: "field not allowed" are somewhat correct (it is also a list), but
   313  are already covered by the other error message and should be elided.
   314  This may lead to a large number of errors otherwise.
   315  -- out/eval --
   316  Errors:
   317  issue1972.err1: conflicting values [] and {someCondition:_,patchs:[...{}],patchs,if someCondition {patchs:_}} (mismatched types list and struct):
   318      ./in.cue:54:12
   319      ./in.cue:61:8
   320  wrongConcreteType: cannot use 2 (type int) as type bool:
   321      ./in.cue:4:2
   322      ./in.cue:1:8
   323  wrongType: cannot use int (type int) as type bool:
   324      ./in.cue:10:2
   325      ./in.cue:1:14
   326  issue1972.err1: invalid list index someCondition (type string):
   327      ./in.cue:65:6
   328  
   329  Result:
   330  (_|_){
   331    // [eval]
   332    a: (struct){
   333      b: (int){ 2 }
   334      c: (int){ int }
   335    }
   336    wrongConcreteType: (_|_){
   337      // [eval] wrongConcreteType: cannot use 2 (type int) as type bool:
   338      //     ./in.cue:4:2
   339      //     ./in.cue:1:8
   340    }
   341    wrongType: (_|_){
   342      // [eval] wrongType: cannot use int (type int) as type bool:
   343      //     ./in.cue:10:2
   344      //     ./in.cue:1:14
   345    }
   346    incomplete: (_|_){
   347      // [incomplete] incomplete: undefined field: d:
   348      //     ./in.cue:16:7
   349      // incomplete: undefined field: d:
   350      //     ./in.cue:23:21
   351      list: (#list){
   352        0: (int){ 1 }
   353        1: (int){ 2 }
   354        2: (int){ 3 }
   355      }
   356    }
   357    useDefault: (struct){
   358      a: (struct){
   359        x: (string){ |(*(string){ "foo" }, (string){ string }) }
   360        y: (string){ |(*(string){ "foo" }, (string){ string }) }
   361      }
   362      issue809: (struct){
   363        #A: (#struct){
   364          a: (string){ string }
   365          b: (string){ string }
   366        }
   367        s: (struct){
   368          bar: (#struct){
   369            a: (string){ "bar" }
   370            b: (string){ |(*(string){ "bar" }, (string){ string }) }
   371          }
   372        }
   373        foo: (#list){
   374          0: (#struct){
   375            a: (string){ "bar" }
   376            b: (string){ |(*(string){ "bar" }, (string){ string }) }
   377          }
   378        }
   379      }
   380    }
   381    issue1972: (_|_){
   382      // [eval]
   383      err1: (_|_){
   384        // [eval] issue1972.err1: conflicting values [] and {someCondition:_,patchs:[...{}],patchs,if someCondition {patchs:_}} (mismatched types list and struct):
   385        //     ./in.cue:54:12
   386        //     ./in.cue:61:8
   387        // issue1972.err1: invalid list index someCondition (type string):
   388        //     ./in.cue:65:6
   389        #patchs: (#list){
   390        }
   391        someCondition: (_){ _ }
   392        patchs: (list){
   393        }
   394        #someCondition: (_){ _ }
   395      }
   396    }
   397  }