github.com/joomcode/cue@v0.4.4-0.20221111115225-539fe3512047/cue/testdata/cycle/issue429.txtar (about) 1 TODO: a bound value resolving to a disjunction should probably 2 be an error. In this case #Size.amx should resolve. 3 4 -- in.cue -- 5 // Range disjunction without cycle (checks only one-way). 6 #Size: { 7 res: uint | *0 8 min: >res | *(1 + res) 9 max: >min | *min 10 } 11 12 s0: #Size & {res: 1} 13 // This discards the default for max. This is correct, but unfortunate. 14 // TODO: is there a tweak to the default mechanism possible that would fix that? 15 // Tread very carefully, though! Perhaps we could have a builtin that 16 // discards any default, so that we can at least manually override this 17 // behavior. 18 s1: #Size & {min: 5} 19 s2: #Size & {max: 5} 20 s3: #Size & { 21 min: 5 22 max: 10 23 } 24 es3: #Size & { 25 min: 10 26 max: 5 27 } 28 29 // Disjunctions with cycles 30 // TODO: improve error message here. Logic is correct, though. 31 #nonEmptyRange: { 32 min: *1 | int 33 min: <max 34 max: >min 35 } 36 r1: #nonEmptyRange & { 37 min: 3 38 } 39 r2: #nonEmptyRange & { 40 max: 5 41 } 42 r3: #nonEmptyRange & { 43 min: 3 44 max: 6 45 } 46 47 er3: #nonEmptyRange & { 48 min: 5 49 max: 5 50 } 51 -- out/eval -- 52 Errors: 53 er3.min: 2 errors in empty disjunction: 54 er3.min: conflicting values 1 and 5: 55 ./in.cue:28:8 56 ./in.cue:43:6 57 ./in.cue:44:7 58 es3.max: 3 errors in empty disjunction: 59 es3.max: conflicting values 1 and 5: 60 ./in.cue:4:16 61 ./in.cue:5:15 62 ./in.cue:20:6 63 ./in.cue:22:7 64 es3.max: conflicting values 10 and 5: 65 ./in.cue:5:15 66 ./in.cue:20:6 67 ./in.cue:21:7 68 ./in.cue:22:7 69 es3.max: invalid value 5 (out of bound >10): 70 ./in.cue:5:7 71 ./in.cue:22:7 72 er3.max: invalid value 5 (out of bound >5): 73 ./in.cue:30:7 74 ./in.cue:45:7 75 76 Result: 77 (_|_){ 78 // [eval] 79 #Size: (#struct){ 80 res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) } 81 min: (number){ |(*(int){ 1 }, (number){ >0 }) } 82 max: (number){ |(*(int){ 1 }, (number){ >0 }, (number){ >1 }) } 83 } 84 s0: (#struct){ 85 res: (int){ 1 } 86 min: (number){ |(*(int){ 2 }, (number){ >1 }) } 87 max: (number){ |(*(int){ 2 }, (number){ >1 }, (number){ >2 }) } 88 } 89 s1: (#struct){ 90 res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) } 91 min: (int){ 5 } 92 max: (number){ |(*(int){ 5 }, (number){ >5 }) } 93 } 94 s2: (#struct){ 95 res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) } 96 min: (number){ |(*(int){ 1 }, (number){ >0 }) } 97 max: (int){ 5 } 98 } 99 s3: (#struct){ 100 res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) } 101 min: (int){ 5 } 102 max: (int){ 10 } 103 } 104 es3: (_|_){ 105 // [eval] 106 res: (int){ |(*(int){ 0 }, (int){ &(>=0, int) }) } 107 min: (int){ 10 } 108 max: (_|_){ 109 // [eval] es3.max: 3 errors in empty disjunction: 110 // es3.max: conflicting values 1 and 5: 111 // ./in.cue:4:16 112 // ./in.cue:5:15 113 // ./in.cue:20:6 114 // ./in.cue:22:7 115 // es3.max: conflicting values 10 and 5: 116 // ./in.cue:5:15 117 // ./in.cue:20:6 118 // ./in.cue:21:7 119 // ./in.cue:22:7 120 // es3.max: invalid value 5 (out of bound >10): 121 // ./in.cue:5:7 122 // ./in.cue:22:7 123 } 124 } 125 #nonEmptyRange: (#struct){ 126 min: (_|_){ 127 // [incomplete] #nonEmptyRange.min: incomplete cause disjunction 128 } 129 max: (_|_){ 130 // [incomplete] #nonEmptyRange.min: incomplete cause disjunction 131 } 132 } 133 r1: (#struct){ 134 min: (int){ 3 } 135 max: (number){ >3 } 136 } 137 r2: (#struct){ 138 min: (int){ |(*(int){ 1 }, (int){ &(<5, int) }) } 139 max: (int){ 5 } 140 } 141 r3: (#struct){ 142 min: (int){ 3 } 143 max: (int){ 6 } 144 } 145 er3: (_|_){ 146 // [eval] 147 min: (_|_){ 148 // [eval] er3.min: 2 errors in empty disjunction: 149 // er3.min: conflicting values 1 and 5: 150 // ./in.cue:28:8 151 // ./in.cue:43:6 152 // ./in.cue:44:7 153 // er3.max: invalid value 5 (out of bound >5): 154 // ./in.cue:30:7 155 // ./in.cue:45:7 156 } 157 max: (_|_){ 158 // [eval] er3.max: invalid value 5 (out of bound >5): 159 // ./in.cue:30:7 160 // ./in.cue:45:7 161 } 162 } 163 } 164 -- out/compile -- 165 --- in.cue 166 { 167 #Size: { 168 res: (&(int, >=0)|*0) 169 min: (>〈0;res〉|*(1 + 〈0;res〉)) 170 max: (>〈0;min〉|*〈0;min〉) 171 } 172 s0: (〈0;#Size〉 & { 173 res: 1 174 }) 175 s1: (〈0;#Size〉 & { 176 min: 5 177 }) 178 s2: (〈0;#Size〉 & { 179 max: 5 180 }) 181 s3: (〈0;#Size〉 & { 182 min: 5 183 max: 10 184 }) 185 es3: (〈0;#Size〉 & { 186 min: 10 187 max: 5 188 }) 189 #nonEmptyRange: { 190 min: (*1|int) 191 min: <〈0;max〉 192 max: >〈0;min〉 193 } 194 r1: (〈0;#nonEmptyRange〉 & { 195 min: 3 196 }) 197 r2: (〈0;#nonEmptyRange〉 & { 198 max: 5 199 }) 200 r3: (〈0;#nonEmptyRange〉 & { 201 min: 3 202 max: 6 203 }) 204 er3: (〈0;#nonEmptyRange〉 & { 205 min: 5 206 max: 5 207 }) 208 }