go/types: don't override x.mode before using it

Changing the mode of x before using the old value is clearly wrong.
And x is not needed anymore afterward so besides being misplaced,
the assignment is not needed in the first place.

Tested manually as it's a bit complicated to set up a test.

Needs to be back-ported to 1.17.

Fixes #47777.

Change-Id: I06f1fa9443eb98009b4276f566d557fd52f1d6d3
Reviewed-on: https://go-review.googlesource.com/c/go/+/343809
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Robert Griesemer 2021-08-19 21:35:57 -07:00
parent c9912780ab
commit e17439e087

View file

@ -223,7 +223,6 @@ func (check *Checker) exprList(elist []ast.Expr, allowCommaOk bool) (xlist []*op
// exactly one (possibly invalid or comma-ok) value
xlist = []*operand{&x}
if allowCommaOk && (x.mode == mapindex || x.mode == commaok || x.mode == commaerr) {
x.mode = value
x2 := &operand{mode: value, expr: e, typ: Typ[UntypedBool]}
if x.mode == commaerr {
x2.typ = universeError