cuelang.org/go@v0.13.0/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  wrongConcreteType: cannot use 2 (type int) as type bool:
   165      ./in.cue:4:2
   166      ./in.cue:1:8
   167  wrongType: cannot use int (type int) as type bool:
   168      ./in.cue:10:2
   169      ./in.cue:1:14
   170  
   171  Result:
   172  (_|_){
   173    // [eval]
   174    a: (struct){
   175      b: (int){ 2 }
   176      c: (int){ int }
   177    }
   178    wrongConcreteType: (_|_){
   179      // [eval] wrongConcreteType: cannot use 2 (type int) as type bool:
   180      //     ./in.cue:4:2
   181      //     ./in.cue:1:8
   182    }
   183    wrongType: (_|_){
   184      // [eval] wrongType: cannot use int (type int) as type bool:
   185      //     ./in.cue:10:2
   186      //     ./in.cue:1:14
   187    }
   188    incomplete: (_|_){
   189      // [incomplete] incomplete: undefined field: d:
   190      //     ./in.cue:16:7
   191      // incomplete: undefined field: d:
   192      //     ./in.cue:23:21
   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        #patchs: (_|_){// []
   230        }
   231        #someCondition: (_){ _ }
   232        someCondition: (_){ _ }
   233        patchs: (_|_){// [
   234          //   ...{},
   235          // ][e] & if 〈0;someCondition〉 _
   236        }
   237      }
   238    }
   239  }
   240  -- diff/-out/evalalpha<==>+out/eval --
   241  diff old new
   242  --- old
   243  +++ new
   244  @@ -1,7 +1,7 @@
   245   Errors:
   246  -issue1972.err1: conflicting values [] and {someCondition:_,patchs:[...{}],patchs,if someCondition {patchs:_}} (mismatched types list and struct):
   247  -    ./in.cue:54:12
   248  +issue1972.err1: conflicting values [...{}] and {someCondition:_,patchs:[...{}],patchs,if someCondition {patchs:_}} (mismatched types list and struct):
   249       ./in.cue:61:8
   250  +    ./in.cue:63:11
   251   wrongConcreteType: cannot use 2 (type int) as type bool:
   252       ./in.cue:4:2
   253       ./in.cue:1:8
   254  @@ -8,8 +8,6 @@
   255   wrongType: cannot use int (type int) as type bool:
   256       ./in.cue:10:2
   257       ./in.cue:1:14
   258  -issue1972.err1: invalid list index someCondition (type string):
   259  -    ./in.cue:65:6
   260   
   261   Result:
   262   (_|_){
   263  @@ -66,17 +64,17 @@
   264     issue1972: (_|_){
   265       // [eval]
   266       err1: (_|_){
   267  -      // [eval] issue1972.err1: conflicting values [] and {someCondition:_,patchs:[...{}],patchs,if someCondition {patchs:_}} (mismatched types list and struct):
   268  -      //     ./in.cue:54:12
   269  +      // [eval] issue1972.err1: conflicting values [...{}] and {someCondition:_,patchs:[...{}],patchs,if someCondition {patchs:_}} (mismatched types list and struct):
   270         //     ./in.cue:61:8
   271  -      // issue1972.err1: invalid list index someCondition (type string):
   272  -      //     ./in.cue:65:6
   273  -      #patchs: (#list){
   274  -      }
   275  -      someCondition: (_){ _ }
   276  -      patchs: (list){
   277  +      //     ./in.cue:63:11
   278  +      #patchs: (_|_){// []
   279         }
   280         #someCondition: (_){ _ }
   281  +      someCondition: (_){ _ }
   282  +      patchs: (_|_){// [
   283  +        //   ...{},
   284  +        // ][e] & if 〈0;someCondition〉 _
   285  +      }
   286       }
   287     }
   288   }
   289  -- diff/todo/p2 --
   290  issue1972: "field not allowed" are somewhat correct (it is also a list), but
   291  are already covered by the other error message and should be elided.
   292  This may lead to a large number of errors otherwise.
   293  -- out/eval --
   294  Errors:
   295  issue1972.err1: conflicting values [] and {someCondition:_,patchs:[...{}],patchs,if someCondition {patchs:_}} (mismatched types list and struct):
   296      ./in.cue:54:12
   297      ./in.cue:61:8
   298  wrongConcreteType: cannot use 2 (type int) as type bool:
   299      ./in.cue:4:2
   300      ./in.cue:1:8
   301  wrongType: cannot use int (type int) as type bool:
   302      ./in.cue:10:2
   303      ./in.cue:1:14
   304  issue1972.err1: invalid list index someCondition (type string):
   305      ./in.cue:65:6
   306  
   307  Result:
   308  (_|_){
   309    // [eval]
   310    a: (struct){
   311      b: (int){ 2 }
   312      c: (int){ int }
   313    }
   314    wrongConcreteType: (_|_){
   315      // [eval] wrongConcreteType: cannot use 2 (type int) as type bool:
   316      //     ./in.cue:4:2
   317      //     ./in.cue:1:8
   318    }
   319    wrongType: (_|_){
   320      // [eval] wrongType: cannot use int (type int) as type bool:
   321      //     ./in.cue:10:2
   322      //     ./in.cue:1:14
   323    }
   324    incomplete: (_|_){
   325      // [incomplete] incomplete: undefined field: d:
   326      //     ./in.cue:16:7
   327      // incomplete: undefined field: d:
   328      //     ./in.cue:23:21
   329      list: (#list){
   330        0: (int){ 1 }
   331        1: (int){ 2 }
   332        2: (int){ 3 }
   333      }
   334    }
   335    useDefault: (struct){
   336      a: (struct){
   337        x: (string){ |(*(string){ "foo" }, (string){ string }) }
   338        y: (string){ |(*(string){ "foo" }, (string){ string }) }
   339      }
   340      issue809: (struct){
   341        #A: (#struct){
   342          a: (string){ string }
   343          b: (string){ string }
   344        }
   345        s: (struct){
   346          bar: (#struct){
   347            a: (string){ "bar" }
   348            b: (string){ |(*(string){ "bar" }, (string){ string }) }
   349          }
   350        }
   351        foo: (#list){
   352          0: (#struct){
   353            a: (string){ "bar" }
   354            b: (string){ |(*(string){ "bar" }, (string){ string }) }
   355          }
   356        }
   357      }
   358    }
   359    issue1972: (_|_){
   360      // [eval]
   361      err1: (_|_){
   362        // [eval] issue1972.err1: conflicting values [] and {someCondition:_,patchs:[...{}],patchs,if someCondition {patchs:_}} (mismatched types list and struct):
   363        //     ./in.cue:54:12
   364        //     ./in.cue:61:8
   365        // issue1972.err1: invalid list index someCondition (type string):
   366        //     ./in.cue:65:6
   367        #patchs: (#list){
   368        }
   369        someCondition: (_){ _ }
   370        patchs: (list){
   371        }
   372        #someCondition: (_){ _ }
   373      }
   374    }
   375  }