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