mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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:
parent
ba1109feb5
commit
13bb48e6fb
2 changed files with 7 additions and 1 deletions
|
|
@ -1083,7 +1083,10 @@ func match0(x, y Value) (_, _ Value) {
|
||||||
return rtof(x1), y
|
return rtof(x1), y
|
||||||
}
|
}
|
||||||
case complexVal:
|
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
|
// force unknown and invalid values into "x position" in callers of match
|
||||||
|
|
|
||||||
|
|
@ -617,6 +617,9 @@ func TestUnknown(t *testing.T) {
|
||||||
if got := Compare(x, token.EQL, y); got {
|
if got := Compare(x, token.EQL, y); got {
|
||||||
t.Errorf("%s == %s: got true; want false", x, y)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue