github.com/solo-io/cue@v0.4.7/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  -- out/compile --
    54  --- in.cue
    55  {
    56    a: {
    57      b: 2
    58      c: int
    59    }
    60    wrongConcreteType: {
    61      if 〈1;a〉.b {
    62        2
    63      }
    64    }
    65    wrongType: {
    66      if 〈1;a〉.c {
    67        2
    68      }
    69    }
    70    incomplete: {
    71      if 〈1;a〉.d {
    72        2
    73      }
    74    }
    75    incomplete: {
    76      list: [
    77        1,
    78        2,
    79        3,
    80      ]
    81      for _, x in 〈0;list〉 if 〈2;a〉.d {
    82        〈1;x〉
    83      }
    84    }
    85    useDefault: {
    86      a: {
    87        x: (*"foo"|string)
    88        if (〈0;x〉 != _|_(explicit error (_|_ literal) in source)) {
    89          y: 〈1;x〉
    90        }
    91      }
    92      issue809: {
    93        #A: {
    94          a: string
    95          b: (*〈0;a〉|string)
    96        }
    97        s: {
    98          [string]: (〈1;#A〉 & {
    99            a: 〈1;-〉
   100          })
   101        }
   102        s: {
   103          bar: _
   104        }
   105        foo: [
   106          for _, a in 〈0;s〉 if (〈0;a〉.b != _|_(explicit error (_|_ literal) in source)) {
   107            〈1;a〉
   108          },
   109        ]
   110      }
   111    }
   112  }
   113  -- out/eval --
   114  Errors:
   115  wrongConcreteType: cannot use 2 (type int) as type bool:
   116      ./in.cue:4:2
   117      ./in.cue:1:9
   118  wrongType: cannot use int (type int) as type bool:
   119      ./in.cue:10:2
   120  
   121  Result:
   122  (_|_){
   123    // [eval]
   124    a: (struct){
   125      b: (int){ 2 }
   126      c: (int){ int }
   127    }
   128    wrongConcreteType: (_|_){
   129      // [eval] wrongConcreteType: cannot use 2 (type int) as type bool:
   130      //     ./in.cue:4:2
   131      //     ./in.cue:1:9
   132    }
   133    wrongType: (_|_){
   134      // [eval] wrongType: cannot use int (type int) as type bool:
   135      //     ./in.cue:10:2
   136    }
   137    incomplete: (_|_){
   138      // [incomplete] incomplete: undefined field: d:
   139      //     ./in.cue:16:7
   140      // incomplete: undefined field: d:
   141      //     ./in.cue:23:21
   142      list: (#list){
   143        0: (int){ 1 }
   144        1: (int){ 2 }
   145        2: (int){ 3 }
   146      }
   147    }
   148    useDefault: (struct){
   149      a: (struct){
   150        x: (string){ |(*(string){ "foo" }, (string){ string }) }
   151        y: (string){ |(*(string){ "foo" }, (string){ string }) }
   152      }
   153      issue809: (struct){
   154        #A: (#struct){
   155          a: (string){ string }
   156          b: (string){ string }
   157        }
   158        s: (struct){
   159          bar: (#struct){
   160            a: (string){ "bar" }
   161            b: (string){ |(*(string){ "bar" }, (string){ string }) }
   162          }
   163        }
   164        foo: (#list){
   165          0: (#struct){
   166            a: (string){ "bar" }
   167            b: (string){ |(*(string){ "bar" }, (string){ string }) }
   168          }
   169        }
   170      }
   171    }
   172  }