From 13bb48e6fbc35419a28747688426eb3684242fbc Mon Sep 17 00:00:00 2001 From: goto1134 <1134togo@gmail.com> Date: Mon, 25 Aug 2025 15:41:53 +0000 Subject: [PATCH] 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: 858ba89a91bf966223975541af739ab0ab977075 GitHub-Pull-Request: golang/go#75140 Reviewed-on: https://go-review.googlesource.com/c/go/+/698955 Reviewed-by: Sean Liao LUCI-TryBot-Result: Go LUCI Auto-Submit: Sean Liao Reviewed-by: Cherry Mui Reviewed-by: Alan Donovan --- src/go/constant/value.go | 5 ++++- src/go/constant/value_test.go | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/go/constant/value.go b/src/go/constant/value.go index 3f1fd3cac8..fb9a0523ce 100644 --- a/src/go/constant/value.go +++ b/src/go/constant/value.go @@ -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 diff --git a/src/go/constant/value_test.go b/src/go/constant/value_test.go index e41315ee27..0f50281ee2 100644 --- a/src/go/constant/value_test.go +++ b/src/go/constant/value_test.go @@ -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) + } } } } -- 2.52.0