cuelang.org/go@v0.10.1/cue/testdata/comprehensions/issue2481.txtar (about) 1 2 -- in.cue -- 3 // Mixing struct fields and embedded scalars should error. Using comprehensions 4 // this follows a different path which may miss the error. 5 // TODO: fix 6 out: { 7 for k in keys { 8 if values[k] != _|_ { 9 val: k 10 if val != _|_ { 11 k 12 } 13 } 14 } 15 } 16 17 // multiple lets are mapped to the same location and will conflict. This is 18 // fine, though, as lets do not represent a single data field. This should 19 // therefore not error. 20 // TODO: fix 21 multiLets: { 22 for k in keys { 23 if values[k] != _|_ { 24 let val = k 25 if val != _|_ { 26 k 27 } 28 } 29 } 30 } 31 32 keys: [ 33 // order matters 34 "a", 35 "b", 36 ] 37 38 values: { 39 // order does not matter 40 "b": "member" 41 "c": "foo" 42 } 43 44 full: { 45 out: { 46 47 // changing this to a list of the keys "fixes" things, i.e. this comprehension is required 48 for k, _ in #github_team_membership { 49 50 // Remove this comprehension to trigger a different type of cycle error 51 if ( values[k] != _|_ ) { 52 53 // This let is also required 54 let val = values[k] 55 56 if val != null && ((val & string) != _|_) { 57 (k): val 58 } 59 } 60 } 61 } 62 63 #github_team_membership: { 64 team_id: string 65 role: string 66 } 67 68 values: { 69 "role": "member" 70 "username": "foo" 71 } 72 } 73 -- out/eval/stats -- 74 Leaks: 3 75 Freed: 23 76 Reused: 17 77 Allocs: 9 78 Retain: 58 79 80 Unifications: 26 81 Conjuncts: 50 82 Disjuncts: 56 83 -- out/eval -- 84 Errors: 85 out: cannot combine regular field "val" with "b": 86 ./in.cue:33:2 87 88 Result: 89 (_|_){ 90 // [eval] 91 out: (_|_){ 92 // [eval] out: cannot combine regular field "val" with "b": 93 // ./in.cue:33:2 94 val: (string){ "b" } 95 } 96 multiLets: (string){ 97 "b" 98 let val#1multi = 〈2;k〉 99 } 100 keys: (#list){ 101 0: (string){ "a" } 102 1: (string){ "b" } 103 } 104 values: (struct){ 105 b: (string){ "member" } 106 c: (string){ "foo" } 107 } 108 full: (struct){ 109 out: (struct){ 110 let val#2multi = 〈4;values〉[〈2;k〉] 111 role: (string){ "member" } 112 } 113 #github_team_membership: (#struct){ 114 team_id: (string){ string } 115 role: (string){ string } 116 } 117 values: (struct){ 118 role: (string){ "member" } 119 username: (string){ "foo" } 120 } 121 } 122 } 123 -- out/compile -- 124 --- in.cue 125 { 126 out: { 127 for _, k in 〈1;keys〉 { 128 if (〈3;values〉[〈1;k〉] != _|_(explicit error (_|_ literal) in source)) { 129 val: 〈2;k〉 130 if (〈0;val〉 != _|_(explicit error (_|_ literal) in source)) { 131 〈3;k〉 132 } 133 } 134 } 135 } 136 multiLets: { 137 for _, k in 〈1;keys〉 { 138 if (〈3;values〉[〈1;k〉] != _|_(explicit error (_|_ literal) in source)) { 139 let val#1multi = 〈2;k〉 140 if (〈0;let val#1〉 != _|_(explicit error (_|_ literal) in source)) { 141 〈3;k〉 142 } 143 } 144 } 145 } 146 keys: [ 147 "a", 148 "b", 149 ] 150 values: { 151 b: "member" 152 c: "foo" 153 } 154 full: { 155 out: { 156 for k, _ in 〈1;#github_team_membership〉 { 157 if (〈3;values〉[〈1;k〉] != _|_(explicit error (_|_ literal) in source)) { 158 let val#2multi = 〈4;values〉[〈2;k〉] 159 if ((〈0;let val#2〉 != null) && ((〈0;let val#2〉 & string) != _|_(explicit error (_|_ literal) in source))) { 160 〈3;k〉: 〈1;let val#2〉 161 } 162 } 163 } 164 } 165 #github_team_membership: { 166 team_id: string 167 role: string 168 } 169 values: { 170 role: "member" 171 username: "foo" 172 } 173 } 174 }