go/constant: fix complex != unknown comparison

By the contract of Compare, if one operand is Unknown, the result must be
false.

Fixes #75137

Change-Id: I56420fae808395f89769f5e5d448f9e1df9a622f
GitHub-Last-Rev: 858ba89a91
GitHub-Pull-Request: golang/go#75140
Reviewed-on: https://go-review.googlesource.com/c/go/+/698955
Reviewed-by: Sean Liao <sean@liao.dev>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Sean Liao <sean@liao.dev>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
goto1134 2025-08-25 15:41:53 +00:00 committed by Gopher Robot
parent ba1109feb5
commit 13bb48e6fb
2 changed files with 7 additions and 1 deletions

View file

@ -1083,7 +1083,10 @@ func match0(x, y Value) (_, _ Value) {
return rtof(x1), y
}
case complexVal:
return vtoc(x), y
switch x1 := x.(type) {
case int64Val, intVal, ratVal, floatVal:
return vtoc(x1), y
}
}
// force unknown and invalid values into "x position" in callers of match

View file

@ -617,6 +617,9 @@ func TestUnknown(t *testing.T) {
if got := Compare(x, token.EQL, y); got {
t.Errorf("%s == %s: got true; want false", x, y)
}
if got := Compare(x, token.NEQ, y); got {
t.Errorf("%s != %s: got true; want false", x, y)
}
}
}
}