]> Cypherpunks repositories - gostls13.git/commitdiff
go/constant: fix complex != unknown comparison
authorgoto1134 <1134togo@gmail.com>
Mon, 25 Aug 2025 15:41:53 +0000 (15:41 +0000)
committerGopher Robot <gobot@golang.org>
Fri, 29 Aug 2025 00:14:30 +0000 (17:14 -0700)
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 <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>
src/go/constant/value.go
src/go/constant/value_test.go

index 3f1fd3cac80281e45e8c78addc2f5f83899b48fd..fb9a0523ced63d111a9fa643ebb5ae4d0b428d1d 100644 (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
index e41315ee27c7164d2134f8e28490bd218bd5a812..0f50281ee27988b9174b5053056589b4ae45d3c0 100644 (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)
+                       }
                }
        }
 }