github.com/joomcode/cue@v0.4.4-0.20221111115225-539fe3512047/cue/testdata/builtins/incomplete.txtar (about) 1 -- in.cue -- 2 import ( 3 "list" 4 "strings" 5 "text/template" 6 ) 7 8 list1: { 9 // Note that Top is not incomplete, only its first element is. 10 // We allow FlattenN to proceed and pass on the incomplete values. 11 Out1: list.FlattenN(Top, 1) 12 Out2: [...] & list.FlattenN(Top, 1) 13 Out3: list.FlattenN(Top, 1) & [...] 14 15 // This evaluates to a list with an incomplete element. 16 Top: [ 17 [ for _, F in _Sub {F}], 18 ] 19 20 _Sub: a.b 21 a: {} // b does not 22 } 23 24 list2: { 25 Out1: list.FlattenN(_Top, 1) 26 Out2: [...] & list.FlattenN(_Top, 1) 27 Out3: list.FlattenN(_Top, 1) & [...] 28 29 // This evaluates to a list with an incomplete element. 30 _Top: [ 31 for _, F in #Sub {F}, 32 ] 33 34 #Sub: a.b 35 36 a: {} // b does not 37 } 38 39 value1: { 40 a: len('sf' | 'dd') 41 } 42 43 value2: { 44 len('sf' | 'dd') 45 } 46 47 incompleteArgDecimalList: { 48 a: #a & {param: 123} 49 #a: { 50 param: int 51 transformed: +param 52 max: list.Max([transformed]) 53 } 54 } 55 56 incompleteArgStringList: { 57 a: #a & {param: "123"} 58 #a: { 59 param: string 60 transformed: param + "" 61 joined: strings.Join([transformed], "-") 62 } 63 } 64 65 incompleteList: { 66 x: _ 67 decimal: list.Max(x) 68 str: strings.Join(x, "") 69 } 70 71 incompleteListError: { 72 x: y + [] 73 y: _ 74 decimal: list.Max(x) 75 str: strings.Join(x, "") 76 } 77 78 badListType: { 79 x: 2 80 decimal: list.Max(x) 81 str: strings.Join(x, "") 82 } 83 84 badListError: { 85 x: 2 + y 86 y: "foo" 87 decimal: list.Max(x) 88 str: strings.Join(x, "") 89 } 90 91 // Issue #1095 92 // Preserve combined error severity for multiple errors. 93 multipleErrors: { 94 #T: { 95 params: { 96 x: string 97 y: string 98 } 99 out: template.Execute("{{.x}} {{.y}}", params) 100 } 101 } 102 -- out/eval -- 103 Errors: 104 badListType.decimal: cannot use 2 (type int) as list in argument 1 to list.Max: 105 ./in.cue:78:11 106 badListType.str: cannot use 2 (type int) as list in argument 1 to strings.Join: 107 ./in.cue:78:11 108 badListError.x: invalid operands 2 and "foo" to '+' (type int and string): 109 ./in.cue:84:11 110 ./in.cue:85:11 111 112 Result: 113 (_|_){ 114 // [eval] 115 list1: (struct){ 116 Out1: (#list){ 117 0: (_|_){ 118 // [incomplete] list1._Sub: undefined field: b: 119 // ./in.cue:19:10 120 } 121 } 122 Out2: (#list){ 123 0: (_|_){ 124 // [incomplete] list1._Sub: undefined field: b: 125 // ./in.cue:19:10 126 } 127 } 128 Out3: (#list){ 129 0: (_|_){ 130 // [incomplete] list1._Sub: undefined field: b: 131 // ./in.cue:19:10 132 } 133 } 134 Top: (#list){ 135 0: (_|_){ 136 // [incomplete] list1._Sub: undefined field: b: 137 // ./in.cue:19:10 138 } 139 } 140 _Sub: (_|_){ 141 // [incomplete] list1._Sub: undefined field: b: 142 // ./in.cue:19:10 143 } 144 a: (struct){ 145 } 146 } 147 list2: (struct){ 148 Out1: (_|_){ 149 // [incomplete] list2.#Sub: undefined field: b: 150 // ./in.cue:33:10 151 } 152 Out2: (_|_){ 153 // [incomplete] list2.#Sub: undefined field: b: 154 // ./in.cue:33:10 155 } 156 Out3: (_|_){ 157 // [incomplete] list2.#Sub: undefined field: b: 158 // ./in.cue:33:10 159 } 160 _Top: (_|_){ 161 // [incomplete] list2.#Sub: undefined field: b: 162 // ./in.cue:33:10 163 } 164 #Sub: (_|_){ 165 // [incomplete] list2.#Sub: undefined field: b: 166 // ./in.cue:33:10 167 } 168 a: (struct){ 169 } 170 } 171 value1: (struct){ 172 a: (_|_){ 173 // [incomplete] value1.a: unresolved disjunction 'sf' | 'dd' (type bytes): 174 // ./in.cue:39:5 175 } 176 } 177 value2: (_|_){ 178 // [incomplete] value2: unresolved disjunction 'sf' | 'dd' (type bytes): 179 // ./in.cue:43:2 180 } 181 incompleteArgDecimalList: (struct){ 182 a: (#struct){ 183 param: (int){ 123 } 184 transformed: (int){ 123 } 185 max: (int){ 123 } 186 } 187 #a: (#struct){ 188 param: (int){ int } 189 transformed: (_|_){ 190 // [incomplete] incompleteArgDecimalList.#a.transformed: operand param of '+' not concrete (was int): 191 // ./in.cue:50:17 192 } 193 max: (_|_){ 194 // [incomplete] incompleteArgDecimalList.#a.0: operand param of '+' not concrete (was int): 195 // ./in.cue:50:17 196 } 197 } 198 } 199 incompleteArgStringList: (struct){ 200 a: (#struct){ 201 param: (string){ "123" } 202 transformed: (string){ "123" } 203 joined: (string){ "123" } 204 } 205 #a: (#struct){ 206 param: (string){ string } 207 transformed: (_|_){ 208 // [incomplete] incompleteArgStringList.#a.transformed: non-concrete value string in operand to +: 209 // ./in.cue:59:16 210 // ./in.cue:58:16 211 } 212 joined: (_|_){ 213 // [incomplete] incompleteArgStringList.#a.0: non-concrete value string in operand to +: 214 // ./in.cue:59:16 215 // ./in.cue:58:16 216 } 217 } 218 } 219 incompleteList: (struct){ 220 x: (_){ _ } 221 decimal: (_|_){ 222 // [incomplete] incompleteList.decimal: non-concrete list for argument 0: 223 // ./in.cue:66:11 224 } 225 str: (_|_){ 226 // [incomplete] incompleteList.str: non-concrete list for argument 0: 227 // ./in.cue:67:11 228 } 229 } 230 incompleteListError: (struct){ 231 x: (_|_){ 232 // [incomplete] incompleteListError.x: non-concrete value _ in operand to +: 233 // ./in.cue:71:11 234 // ./in.cue:72:11 235 } 236 y: (_){ _ } 237 decimal: (_|_){ 238 // [incomplete] incompleteListError.x: non-concrete value _ in operand to +: 239 // ./in.cue:71:11 240 // ./in.cue:72:11 241 } 242 str: (_|_){ 243 // [incomplete] incompleteListError.x: non-concrete value _ in operand to +: 244 // ./in.cue:71:11 245 // ./in.cue:72:11 246 } 247 } 248 badListType: (_|_){ 249 // [eval] 250 x: (int){ 2 } 251 decimal: (_|_){ 252 // [eval] badListType.decimal: cannot use 2 (type int) as list in argument 1 to list.Max: 253 // ./in.cue:78:11 254 } 255 str: (_|_){ 256 // [eval] badListType.str: cannot use 2 (type int) as list in argument 1 to strings.Join: 257 // ./in.cue:78:11 258 } 259 } 260 badListError: (_|_){ 261 // [eval] 262 x: (_|_){ 263 // [eval] badListError.x: invalid operands 2 and "foo" to '+' (type int and string): 264 // ./in.cue:84:11 265 // ./in.cue:85:11 266 } 267 y: (string){ "foo" } 268 decimal: (_|_){ 269 // [eval] badListError.x: invalid operands 2 and "foo" to '+' (type int and string): 270 // ./in.cue:84:11 271 // ./in.cue:85:11 272 } 273 str: (_|_){ 274 // [eval] badListError.x: invalid operands 2 and "foo" to '+' (type int and string): 275 // ./in.cue:84:11 276 // ./in.cue:85:11 277 } 278 } 279 multipleErrors: (struct){ 280 #T: (#struct){ 281 params: (#struct){ 282 x: (string){ string } 283 y: (string){ string } 284 } 285 out: (_|_){ 286 // [incomplete] error in call to text/template.Execute: cannot convert non-concrete value string: 287 // ./in.cue:98:8 288 // ./in.cue:95:4 289 } 290 } 291 } 292 } 293 -- out/compile -- 294 --- in.cue 295 { 296 list1: { 297 Out1: 〈import;list〉.FlattenN(〈0;Top〉, 1) 298 Out2: ([ 299 ..., 300 ] & 〈import;list〉.FlattenN(〈0;Top〉, 1)) 301 Out3: (〈import;list〉.FlattenN(〈0;Top〉, 1) & [ 302 ..., 303 ]) 304 Top: [ 305 [ 306 for _, F in 〈2;_Sub〉 { 307 〈1;F〉 308 }, 309 ], 310 ] 311 _Sub: 〈0;a〉.b 312 a: {} 313 } 314 list2: { 315 Out1: 〈import;list〉.FlattenN(〈0;_Top〉, 1) 316 Out2: ([ 317 ..., 318 ] & 〈import;list〉.FlattenN(〈0;_Top〉, 1)) 319 Out3: (〈import;list〉.FlattenN(〈0;_Top〉, 1) & [ 320 ..., 321 ]) 322 _Top: [ 323 for _, F in 〈1;#Sub〉 { 324 〈1;F〉 325 }, 326 ] 327 #Sub: 〈0;a〉.b 328 a: {} 329 } 330 value1: { 331 a: len(('sf'|'dd')) 332 } 333 value2: { 334 len(('sf'|'dd')) 335 } 336 incompleteArgDecimalList: { 337 a: (〈0;#a〉 & { 338 param: 123 339 }) 340 #a: { 341 param: int 342 transformed: +〈0;param〉 343 max: 〈import;list〉.Max([ 344 〈1;transformed〉, 345 ]) 346 } 347 } 348 incompleteArgStringList: { 349 a: (〈0;#a〉 & { 350 param: "123" 351 }) 352 #a: { 353 param: string 354 transformed: (〈0;param〉 + "") 355 joined: 〈import;strings〉.Join([ 356 〈1;transformed〉, 357 ], "-") 358 } 359 } 360 incompleteList: { 361 x: _ 362 decimal: 〈import;list〉.Max(〈0;x〉) 363 str: 〈import;strings〉.Join(〈0;x〉, "") 364 } 365 incompleteListError: { 366 x: (〈0;y〉 + []) 367 y: _ 368 decimal: 〈import;list〉.Max(〈0;x〉) 369 str: 〈import;strings〉.Join(〈0;x〉, "") 370 } 371 badListType: { 372 x: 2 373 decimal: 〈import;list〉.Max(〈0;x〉) 374 str: 〈import;strings〉.Join(〈0;x〉, "") 375 } 376 badListError: { 377 x: (2 + 〈0;y〉) 378 y: "foo" 379 decimal: 〈import;list〉.Max(〈0;x〉) 380 str: 〈import;strings〉.Join(〈0;x〉, "") 381 } 382 multipleErrors: { 383 #T: { 384 params: { 385 x: string 386 y: string 387 } 388 out: 〈import;"text/template"〉.Execute("{{.x}} {{.y}}", 〈0;params〉) 389 } 390 } 391 }