Skip to content

Commit 59bdbb5

Browse files
mpvlmyitcv
authored andcommitted
internal/core/adt: fix bound simplification for floats
Equal case was not checked for floats. Fixes #1310 Signed-off-by: Marcel van Lohuizen <mpvl@golang.org> Change-Id: Icd5d2aba5080fae3b42a4abd5544ca4c579f29c6 Signed-off-by: Marcel van Lohuizen <mpvl@golang.org> Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/527322 Unity-Result: CUEcueckoo <cueckoo@cuelang.org> TryBot-Result: CUEcueckoo <cueckoo@cuelang.org> Reviewed-by: Paul Jolly <paul@myitcv.io>
1 parent 62e876d commit 59bdbb5

File tree

2 files changed

+93
-39
lines changed

2 files changed

+93
-39
lines changed

cue/testdata/resolve/011_bounds.txtar

Lines changed: 92 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,22 @@ s23e: >0.0 & <2.0 // no simplification
4242

4343
s30: >0 & int
4444

45+
floats: {
46+
[string]: float
47+
f1: <10.0 & <=5.0
48+
f2: <=10.0 & <5.0
49+
f3: <1.1 & <=1.1
50+
f4: <=1.1 & <=1.1
51+
f5: >1.1 & >=1.1
52+
f6: >=1.1 & >1.1
53+
f7: >=1.1 & <=1.1
54+
55+
issue1310: >=2.1 & <=1.0
56+
fe2: >2.1 & <=2.1
57+
58+
fe3: float & >2 & <=3
59+
}
60+
4561
e1: null & !=null
4662
e2: !=null & null
4763
e3: >1 & 1
@@ -126,6 +142,19 @@ e9: _|_ // conflicting values >"a" and <1 (mismatched types string and number)
126142
s23d: (>0 & (int & <2))
127143
s23e: (>0.0 & <2.0)
128144
s30: (>0 & int)
145+
floats: {
146+
[string]: float
147+
f1: (<10.0 & <=5.0)
148+
f2: (<=10.0 & <5.0)
149+
f3: (<1.1 & <=1.1)
150+
f4: (<=1.1 & <=1.1)
151+
f5: (>1.1 & >=1.1)
152+
f6: (>=1.1 & >1.1)
153+
f7: (>=1.1 & <=1.1)
154+
issue1310: (>=2.1 & <=1.0)
155+
fe2: (>2.1 & <=2.1)
156+
fe3: ((float & >2) & <=3)
157+
}
129158
e1: (null & !=null)
130159
e2: (!=null & null)
131160
e3: (>1 & 1)
@@ -139,32 +168,38 @@ e9: _|_ // conflicting values >"a" and <1 (mismatched types string and number)
139168
-- out/eval --
140169
Errors:
141170
e1: conflicting values null and !=null (mismatched types null and (bool|string|bytes|func|list|struct|number)):
142-
./in.cue:40:5
143-
./in.cue:40:12
171+
./in.cue:56:5
172+
./in.cue:56:12
144173
e2: conflicting values !=null and null (mismatched types (bool|string|bytes|func|list|struct|number) and null):
145-
./in.cue:41:5
146-
./in.cue:41:14
174+
./in.cue:57:5
175+
./in.cue:57:14
147176
e5: incompatible bounds >1 and <0:
148-
./in.cue:44:5
149-
./in.cue:44:10
177+
./in.cue:60:5
178+
./in.cue:60:10
150179
e6: incompatible bounds >11 and <11:
151-
./in.cue:45:5
152-
./in.cue:45:11
180+
./in.cue:61:5
181+
./in.cue:61:11
153182
e7: incompatible bounds >=11 and <11:
154-
./in.cue:46:5
155-
./in.cue:46:12
183+
./in.cue:62:5
184+
./in.cue:62:12
156185
e8: incompatible bounds >11 and <=11:
157-
./in.cue:47:5
158-
./in.cue:47:11
186+
./in.cue:63:5
187+
./in.cue:63:11
159188
e9: conflicting values >"a" and <1 (mismatched types string and number):
160-
./in.cue:48:5
161-
./in.cue:48:12
189+
./in.cue:64:5
190+
./in.cue:64:12
191+
floats.fe2: incompatible bounds >2.1 and <=2.1:
192+
./in.cue:51:10
193+
./in.cue:51:17
194+
floats.issue1310: incompatible bounds >=2.1 and <=1.0:
195+
./in.cue:50:16
196+
./in.cue:50:24
162197
e3: invalid value 1 (out of bound >1):
163-
./in.cue:42:5
164-
./in.cue:42:10
198+
./in.cue:58:5
199+
./in.cue:58:10
165200
e4: invalid value 0 (out of bound <0):
166-
./in.cue:43:5
167-
./in.cue:43:10
201+
./in.cue:59:5
202+
./in.cue:59:10
168203

169204
Result:
170205
(_|_){
@@ -199,49 +234,70 @@ Result:
199234
s23d: (int){ 1 }
200235
s23e: (number){ &(>0.0, <2.0) }
201236
s30: (int){ &(>0, int) }
237+
floats: (_|_){
238+
// [eval]
239+
f1: (float){ &(<=5.0, float) }
240+
f2: (float){ &(<5.0, float) }
241+
f3: (float){ &(<1.1, float) }
242+
f4: (float){ &(<=1.1, float) }
243+
f5: (float){ &(>1.1, float) }
244+
f6: (float){ &(>1.1, float) }
245+
f7: (number){ 1.1 }
246+
issue1310: (_|_){
247+
// [eval] floats.issue1310: incompatible bounds >=2.1 and <=1.0:
248+
// ./in.cue:50:16
249+
// ./in.cue:50:24
250+
}
251+
fe2: (_|_){
252+
// [eval] floats.fe2: incompatible bounds >2.1 and <=2.1:
253+
// ./in.cue:51:10
254+
// ./in.cue:51:17
255+
}
256+
fe3: (float){ &(>2, <=3, float) }
257+
}
202258
e1: (_|_){
203259
// [eval] e1: conflicting values null and !=null (mismatched types null and (bool|string|bytes|func|list|struct|number)):
204-
// ./in.cue:40:5
205-
// ./in.cue:40:12
260+
// ./in.cue:56:5
261+
// ./in.cue:56:12
206262
}
207263
e2: (_|_){
208264
// [eval] e2: conflicting values !=null and null (mismatched types (bool|string|bytes|func|list|struct|number) and null):
209-
// ./in.cue:41:5
210-
// ./in.cue:41:14
265+
// ./in.cue:57:5
266+
// ./in.cue:57:14
211267
}
212268
e3: (_|_){
213269
// [eval] e3: invalid value 1 (out of bound >1):
214-
// ./in.cue:42:5
215-
// ./in.cue:42:10
270+
// ./in.cue:58:5
271+
// ./in.cue:58:10
216272
}
217273
e4: (_|_){
218274
// [eval] e4: invalid value 0 (out of bound <0):
219-
// ./in.cue:43:5
220-
// ./in.cue:43:10
275+
// ./in.cue:59:5
276+
// ./in.cue:59:10
221277
}
222278
e5: (_|_){
223279
// [eval] e5: incompatible bounds >1 and <0:
224-
// ./in.cue:44:5
225-
// ./in.cue:44:10
280+
// ./in.cue:60:5
281+
// ./in.cue:60:10
226282
}
227283
e6: (_|_){
228284
// [eval] e6: incompatible bounds >11 and <11:
229-
// ./in.cue:45:5
230-
// ./in.cue:45:11
285+
// ./in.cue:61:5
286+
// ./in.cue:61:11
231287
}
232288
e7: (_|_){
233289
// [eval] e7: incompatible bounds >=11 and <11:
234-
// ./in.cue:46:5
235-
// ./in.cue:46:12
290+
// ./in.cue:62:5
291+
// ./in.cue:62:12
236292
}
237293
e8: (_|_){
238294
// [eval] e8: incompatible bounds >11 and <=11:
239-
// ./in.cue:47:5
240-
// ./in.cue:47:11
295+
// ./in.cue:63:5
296+
// ./in.cue:63:11
241297
}
242298
e9: (_|_){
243299
// [eval] e9: conflicting values >"a" and <1 (mismatched types string and number):
244-
// ./in.cue:48:5
245-
// ./in.cue:48:12
300+
// ./in.cue:64:5
301+
// ./in.cue:64:12
246302
}
247303
}

internal/core/adt/simplify.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ func SimplifyBounds(ctx *OpContext, k Kind, x, y *BoundValue) Value {
128128
// _|_ if b <= a
129129

130130
switch diff, err := d.Int64(); {
131-
case err != nil:
132-
133131
case diff == 1:
134132
if k&FloatKind == 0 {
135133
if x.Op == GreaterEqualOp && y.Op == LessThanOp {
@@ -147,7 +145,7 @@ func SimplifyBounds(ctx *OpContext, k Kind, x, y *BoundValue) Value {
147145

148146
}
149147

150-
case diff == 0:
148+
case diff == 0 && err == nil:
151149
if x.Op == GreaterEqualOp && y.Op == LessEqualOp {
152150
return ctx.newNum(&lo, k&NumKind, x, y)
153151
}

0 commit comments

Comments
 (0)