Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 13bb48e

Browse files
goto1134gopherbot
authored andcommitted
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: 858ba89 GitHub-Pull-Request: #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>
1 parent ba1109f commit 13bb48e

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

‎src/go/constant/value.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,10 @@ func match0(x, y Value) (_, _ Value) {
10831083
return rtof(x1), y
10841084
}
10851085
case complexVal:
1086-
return vtoc(x), y
1086+
switch x1 := x.(type) {
1087+
case int64Val, intVal, ratVal, floatVal:
1088+
return vtoc(x1), y
1089+
}
10871090
}
10881091

10891092
// force unknown and invalid values into "x position" in callers of match

‎src/go/constant/value_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,9 @@ func TestUnknown(t *testing.T) {
617617
if got := Compare(x, token.EQL, y); got {
618618
t.Errorf("%s == %s: got true; want false", x, y)
619619
}
620+
if got := Compare(x, token.NEQ, y); got {
621+
t.Errorf("%s != %s: got true; want false", x, y)
622+
}
620623
}
621624
}
622625
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /