mirror of
https://github.com/golang/go
synced 2024-11-18 14:54:40 -07:00
go/exact: handle unknowns consistently
Fixes golang/go#9147. LGTM=adonovan R=adonovan CC=golang-codereviews https://golang.org/cl/180110043
This commit is contained in:
parent
a9651d6ad7
commit
cc6170934b
@ -560,14 +560,16 @@ func ord(x Value) int {
|
||||
switch x.(type) {
|
||||
default:
|
||||
return 0
|
||||
case int64Val:
|
||||
case boolVal, stringVal:
|
||||
return 1
|
||||
case intVal:
|
||||
case int64Val:
|
||||
return 2
|
||||
case floatVal:
|
||||
case intVal:
|
||||
return 3
|
||||
case complexVal:
|
||||
case floatVal:
|
||||
return 4
|
||||
case complexVal:
|
||||
return 5
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -346,3 +346,30 @@ func TestBytes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnknown(t *testing.T) {
|
||||
u := MakeUnknown()
|
||||
var values = []Value{
|
||||
u,
|
||||
MakeBool(false), // token.ADD ok below, operation is never considered
|
||||
MakeString(""),
|
||||
MakeInt64(1),
|
||||
MakeFromLiteral("-1234567890123456789012345678901234567890", token.INT),
|
||||
MakeFloat64(1.2),
|
||||
MakeImag(MakeFloat64(1.2)),
|
||||
}
|
||||
for _, val := range values {
|
||||
x, y := val, u
|
||||
for i := range [2]int{} {
|
||||
if i == 1 {
|
||||
x, y = y, x
|
||||
}
|
||||
if got := BinaryOp(x, token.ADD, y); got.Kind() != Unknown {
|
||||
t.Errorf("%s + %s: got %s; want %s", x, y, got, u)
|
||||
}
|
||||
if got := Compare(x, token.EQL, y); got {
|
||||
t.Errorf("%s == %s: got true; want false", x, y)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user