Skip to content

Commit e1ceed4

Browse files
committed
internal/core/adt: change semantics of unary_op(basictype)
This seems wrong. New evaluator handles this correctly based on semantics of old evaluator, which means it ends up silently ignoring incomplete errors. The old evaluator was inconsistent here. Rather than mimicing the old behavior, it seems better to adjust the semantics. Note that this is a breaking change. It seems odd to write configurations like this, though, so I don't expect this to be an issue in practice. If it results in any issues, we can revert this change and perhaps adjust the new evaluator accordingly. Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: Iab11975e1ea62a15b0a3f9619b9f0b1a84d7a824 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1172014 Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent 886eefd commit e1ceed4

File tree

3 files changed

+44
-20
lines changed

3 files changed

+44
-20
lines changed

cue/testdata/eval/bounds.txtar

+21-6
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Allocs: 3
7070
Retain: 1
7171

7272
Unifications: 53
73-
Conjuncts: 90
73+
Conjuncts: 110
7474
Disjuncts: 54
7575
-- out/eval --
7676
Errors:
@@ -121,11 +121,26 @@ Result:
121121
i: (int){ int }
122122
f: (float){ float }
123123
b: (bytes){ bytes }
124-
basic1: (int){ int }
125-
basic2: (number){ number }
126-
basic3: (string){ string }
127-
basic4: (float){ float }
128-
basic5: (bytes){ bytes }
124+
basic1: (_|_){
125+
// [incomplete] simplifyExpr.basic1: non-concrete value i for bound <:
126+
// ./in.cue:48:12
127+
}
128+
basic2: (_|_){
129+
// [incomplete] simplifyExpr.basic2: non-concrete value n for bound >:
130+
// ./in.cue:49:12
131+
}
132+
basic3: (_|_){
133+
// [incomplete] simplifyExpr.basic3: non-concrete value s for bound >=:
134+
// ./in.cue:50:13
135+
}
136+
basic4: (_|_){
137+
// [incomplete] simplifyExpr.basic4: non-concrete value f for bound <=:
138+
// ./in.cue:51:13
139+
}
140+
basic5: (_|_){
141+
// [incomplete] simplifyExpr.basic5: non-concrete value b for bound <=:
142+
// ./in.cue:52:13
143+
}
129144
bne1: (_|_){
130145
// [incomplete] simplifyExpr.bne1: non-concrete value s for bound !=:
131146
// ./in.cue:55:11

cue/testdata/eval/incomplete.txtar

+18-13
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ s: string
33

44
e1: s + s
55
e2: >"bar" & s // okay
6-
e3: >s & "foo" // okay
6+
e3: >s & "foo" // not okay
77
e3b: >s
88

99
e4: >e1 & s
@@ -44,15 +44,15 @@ issue1837: {
4444
}
4545
}
4646
-- out/eval/stats --
47-
Leaks: 5
48-
Freed: 27
49-
Reused: 21
50-
Allocs: 11
51-
Retain: 101
47+
Leaks: 0
48+
Freed: 32
49+
Reused: 26
50+
Allocs: 6
51+
Retain: 96
5252

5353
Unifications: 32
54-
Conjuncts: 159
55-
Disjuncts: 50
54+
Conjuncts: 172
55+
Disjuncts: 45
5656
-- out/eval --
5757
(struct){
5858
s: (string){ string }
@@ -62,8 +62,14 @@ Disjuncts: 50
6262
// ./in.cue:1:4
6363
}
6464
e2: (string){ >"bar" }
65-
e3: (string){ "foo" }
66-
e3b: (string){ string }
65+
e3: (_|_){
66+
// [incomplete] e3: non-concrete value s for bound >:
67+
// ./in.cue:5:7
68+
}
69+
e3b: (_|_){
70+
// [incomplete] e3b: non-concrete value s for bound >:
71+
// ./in.cue:6:7
72+
}
6773
e4: (_|_){
6874
// [incomplete] e1: non-concrete value string in operand to +:
6975
// ./in.cue:3:6
@@ -90,9 +96,8 @@ Disjuncts: 50
9096
}
9197
a: (int){ int }
9298
okay: (_|_){
93-
// [incomplete] okay: non-concrete value >10 & int in operand to +:
94-
// ./in.cue:18:7
95-
// ./in.cue:18:8
99+
// [incomplete] non-concrete value a for bound <:
100+
// ./in.cue:18:15
96101
}
97102
issue1837: (struct){
98103
p1: (struct){

internal/core/adt/expr.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,11 @@ func (x *BoundExpr) evaluate(ctx *OpContext, state vertexStatus) Value {
548548
case *BasicType:
549549
switch x.Op {
550550
case LessEqualOp, LessThanOp, GreaterEqualOp, GreaterThanOp:
551-
return y
551+
// TODO: this does not seem correct and results in some weird
552+
// behavior for bounds.
553+
ctx.addErrf(IncompleteError, token.NoPos,
554+
"non-concrete value %s for bound %s", x.Expr, x.Op)
555+
return nil
552556
}
553557
}
554558
if v.Concreteness() > Concrete {

0 commit comments

Comments
 (0)