github.com/joomcode/cue@v0.4.4-0.20221111115225-539fe3512047/cue/testdata/disjunctions/defembed.txtar (about) 1 Interaction between defaults, embedding and disjunctions. 2 3 // TODO: at the moment, using a default will select it. 4 -- in.cue -- 5 x: { 6 // All of these resolve to *2 | 3 7 m1: (1 | (*2 | 3)) & (>=2 & <=3) 8 m2: (1 | (*2 | 3)) & (2 | 3) 9 m3: (*1 | *(*2 | 3)) & (2 | 3) 10 } 11 y1: x & { 12 {m4: x.m1 + x.m2 + x.m3} 13 } 14 y2: { 15 x 16 {m4: y2.m1 + y2.m2 + y2.m3} 17 } 18 Y=y3: { 19 x 20 {m4: Y.m1 + Y.m2 + Y.m3} 21 } 22 y4: x & { 23 {m4: y4.m1 + y4.m2 + y4.m3} 24 } 25 26 // Second disjunct in embedding is not possible because of previous declaration 27 // of `b`, so it should be resolved to {a: 1}. 28 b: (*"a" | "b") | "c" 29 {a: b} | {b: int} 30 -- out/eval -- 31 (struct){ 32 x: (struct){ 33 m1: (int){ |(*(int){ 2 }, (int){ 3 }) } 34 m2: (int){ |(*(int){ 2 }, (int){ 3 }) } 35 m3: (int){ |(*(int){ 2 }, (int){ 3 }) } 36 } 37 y1: (struct){ 38 m1: (int){ |(*(int){ 2 }, (int){ 3 }) } 39 m2: (int){ |(*(int){ 2 }, (int){ 3 }) } 40 m3: (int){ |(*(int){ 2 }, (int){ 3 }) } 41 m4: (int){ 6 } 42 } 43 y2: (struct){ 44 m1: (int){ |(*(int){ 2 }, (int){ 3 }) } 45 m2: (int){ |(*(int){ 2 }, (int){ 3 }) } 46 m3: (int){ |(*(int){ 2 }, (int){ 3 }) } 47 m4: (int){ 6 } 48 } 49 y3: (struct){ 50 m1: (int){ |(*(int){ 2 }, (int){ 3 }) } 51 m2: (int){ |(*(int){ 2 }, (int){ 3 }) } 52 m3: (int){ |(*(int){ 2 }, (int){ 3 }) } 53 m4: (int){ 6 } 54 } 55 y4: (struct){ 56 m1: (int){ |(*(int){ 2 }, (int){ 3 }) } 57 m2: (int){ |(*(int){ 2 }, (int){ 3 }) } 58 m3: (int){ |(*(int){ 2 }, (int){ 3 }) } 59 m4: (int){ 6 } 60 } 61 b: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) } 62 a: (string){ |(*(string){ "a" }, (string){ "b" }, (string){ "c" }) } 63 } 64 -- out/compile -- 65 --- in.cue 66 { 67 x: { 68 m1: ((1|(*2|3)) & (>=2 & <=3)) 69 m2: ((1|(*2|3)) & (2|3)) 70 m3: ((*1|*(*2|3)) & (2|3)) 71 } 72 y1: (〈0;x〉 & { 73 { 74 m4: ((〈2;x〉.m1 + 〈2;x〉.m2) + 〈2;x〉.m3) 75 } 76 }) 77 y2: { 78 〈1;x〉 79 { 80 m4: ((〈2;y2〉.m1 + 〈2;y2〉.m2) + 〈2;y2〉.m3) 81 } 82 } 83 y3: { 84 〈1;x〉 85 { 86 m4: ((〈2;y3〉.m1 + 〈2;y3〉.m2) + 〈2;y3〉.m3) 87 } 88 } 89 y4: (〈0;x〉 & { 90 { 91 m4: ((〈2;y4〉.m1 + 〈2;y4〉.m2) + 〈2;y4〉.m3) 92 } 93 }) 94 b: ((*"a"|"b")|"c") 95 ({ 96 a: 〈1;b〉 97 }|{ 98 b: int 99 }) 100 }