github.com/joomcode/cue@v0.4.4-0.20221111115225-539fe3512047/cue/testdata/scalars/embed.txtar (about) 1 // Issue ##739 2 3 -- in.cue -- 4 import "strings" 5 6 intEmbed: { 7 a1: { 8 2 9 } 10 a2: { 11 v: { 12 3 13 #foo: a2.v + 1 14 } 15 w: v 16 x: v.#foo 17 } 18 a3: a1 + a2.v 19 } 20 21 listEmbed: { 22 a1: { 23 2 24 } 25 b3: { 26 [1, 2] 27 #foo: 1 28 } 29 b4: b3 + b3 30 b5: b3[1] 31 b6: b3[5] 32 b7: b4[a1] // 1 33 } 34 35 stringEmbed: { 36 s1: { 37 "foo" 38 #bar: "bar" 39 } 40 s2: [ s1, {s1.#bar, #baz: 4}] 41 s3: strings.Join(s2, "--") 42 } 43 44 outPattern: { 45 sum: { 46 out: #a + #b 47 #a: int 48 #b: int 49 } 50 used: sum & {#a: 1, #b: 3} 51 } 52 53 arithmetic: { 54 sum: { 55 #a + #b 56 #a: int 57 #b: int 58 } 59 a1: (sum & {_, #a: 1, #b: 3}) + 2 60 a2: 2 + (sum & {_, #a: 1, #b: 3}) 61 a3: 2 + (2 + (sum & {_, #a: 1, #b: 3})) 62 } 63 64 defCheck: { 65 a: { 66 #def: 1 67 } 68 b: a.#def 69 } 70 71 optionalExists: { 72 string | { 73 value?: string 74 75 if value != _|_ { 76 other: int 77 } 78 } 79 } 80 81 optionalCheck: { 82 thing: string | { 83 value?: string 84 85 if value != _|_ { 86 other: int 87 } 88 } 89 90 thing: { 91 value: "some string" 92 other: 3 93 } 94 } 95 96 hidden: { 97 issue794: { 98 _foo: "foo" 99 [_foo] 100 } 101 } 102 -- out/eval -- 103 Errors: 104 listEmbed.b6: invalid list index 5 (out of bounds): 105 ./in.cue:28:9 106 107 Result: 108 (_|_){ 109 // [eval] 110 intEmbed: (struct){ 111 a1: (int){ 2 } 112 a2: (struct){ 113 v: (int){ 114 3 115 #foo: (int){ 4 } 116 } 117 w: (int){ 118 3 119 #foo: (int){ 4 } 120 } 121 x: (int){ 4 } 122 } 123 a3: (int){ 5 } 124 } 125 listEmbed: (_|_){ 126 // [eval] 127 a1: (int){ 2 } 128 b3: (#list){ 129 #foo: (int){ 1 } 130 0: (int){ 1 } 131 1: (int){ 2 } 132 } 133 b4: (#list){ 134 0: (int){ 1 } 135 1: (int){ 2 } 136 2: (int){ 1 } 137 3: (int){ 2 } 138 } 139 b5: (int){ 2 } 140 b6: (_|_){ 141 // [eval] listEmbed.b6: invalid list index 5 (out of bounds): 142 // ./in.cue:28:9 143 } 144 b7: (int){ 1 } 145 } 146 stringEmbed: (struct){ 147 s1: (string){ 148 "foo" 149 #bar: (string){ "bar" } 150 } 151 s2: (#list){ 152 0: (string){ 153 "foo" 154 #bar: (string){ "bar" } 155 } 156 1: (string){ 157 "bar" 158 #baz: (int){ 4 } 159 } 160 } 161 s3: (string){ "foo--bar" } 162 } 163 outPattern: (struct){ 164 sum: (struct){ 165 out: (_|_){ 166 // [incomplete] outPattern.sum.out: non-concrete value int in operand to +: 167 // ./in.cue:43:8 168 // ./in.cue:44:8 169 } 170 #a: (int){ int } 171 #b: (int){ int } 172 } 173 used: (struct){ 174 out: (int){ 4 } 175 #a: (int){ 1 } 176 #b: (int){ 3 } 177 } 178 } 179 arithmetic: (struct){ 180 sum: (_|_){ 181 // [incomplete] arithmetic.sum: non-concrete value int in operand to +: 182 // ./in.cue:52:3 183 // ./in.cue:53:7 184 #a: (int){ int } 185 #b: (int){ int } 186 } 187 a1: (int){ 6 } 188 a2: (int){ 6 } 189 a3: (int){ 8 } 190 } 191 defCheck: (struct){ 192 a: (struct){ 193 #def: (int){ 1 } 194 } 195 b: (int){ 1 } 196 } 197 optionalExists: ((string|struct)){ |((string){ string }, (struct){ 198 }) } 199 optionalCheck: (struct){ 200 thing: (struct){ 201 value: (string){ "some string" } 202 other: (int){ 3 } 203 } 204 } 205 hidden: (struct){ 206 issue794: (#list){ 207 _foo: (string){ "foo" } 208 0: (string){ "foo" } 209 } 210 } 211 } 212 -- out/compile -- 213 --- in.cue 214 { 215 intEmbed: { 216 a1: { 217 2 218 } 219 a2: { 220 v: { 221 3 222 #foo: (〈2;a2〉.v + 1) 223 } 224 w: 〈0;v〉 225 x: 〈0;v〉.#foo 226 } 227 a3: (〈0;a1〉 + 〈0;a2〉.v) 228 } 229 listEmbed: { 230 a1: { 231 2 232 } 233 b3: { 234 [ 235 1, 236 2, 237 ] 238 #foo: 1 239 } 240 b4: (〈0;b3〉 + 〈0;b3〉) 241 b5: 〈0;b3〉[1] 242 b6: 〈0;b3〉[5] 243 b7: 〈0;b4〉[〈0;a1〉] 244 } 245 stringEmbed: { 246 s1: { 247 "foo" 248 #bar: "bar" 249 } 250 s2: [ 251 〈1;s1〉, 252 { 253 〈2;s1〉.#bar 254 #baz: 4 255 }, 256 ] 257 s3: 〈import;strings〉.Join(〈0;s2〉, "--") 258 } 259 outPattern: { 260 sum: { 261 out: (〈0;#a〉 + 〈0;#b〉) 262 #a: int 263 #b: int 264 } 265 used: (〈0;sum〉 & { 266 #a: 1 267 #b: 3 268 }) 269 } 270 arithmetic: { 271 sum: { 272 (〈0;#a〉 + 〈0;#b〉) 273 #a: int 274 #b: int 275 } 276 a1: ((〈0;sum〉 & { 277 _ 278 #a: 1 279 #b: 3 280 }) + 2) 281 a2: (2 + (〈0;sum〉 & { 282 _ 283 #a: 1 284 #b: 3 285 })) 286 a3: (2 + (2 + (〈0;sum〉 & { 287 _ 288 #a: 1 289 #b: 3 290 }))) 291 } 292 defCheck: { 293 a: { 294 #def: 1 295 } 296 b: 〈0;a〉.#def 297 } 298 optionalExists: { 299 (string|{ 300 value?: string 301 if (〈0;value〉 != _|_(explicit error (_|_ literal) in source)) { 302 other: int 303 } 304 }) 305 } 306 optionalCheck: { 307 thing: (string|{ 308 value?: string 309 if (〈0;value〉 != _|_(explicit error (_|_ literal) in source)) { 310 other: int 311 } 312 }) 313 thing: { 314 value: "some string" 315 other: 3 316 } 317 } 318 hidden: { 319 issue794: { 320 _foo: "foo" 321 [ 322 〈1;_foo〉, 323 ] 324 } 325 } 326 }