]> Cypherpunks repositories - gostls13.git/commit
go/types, types2: don't panic for invalid assignments of comma-ok expressions
authorRobert Griesemer <gri@golang.org>
Tue, 18 Apr 2023 22:10:46 +0000 (15:10 -0700)
committerGopher Robot <gobot@golang.org>
Wed, 19 Apr 2023 02:10:00 +0000 (02:10 +0000)
commit969ab34e4629bdda410c8468d4f45a08e4fec9f8
treef714d463640a2cdd572e5eec5ab96c2af31f843e
parent7e66a8ad400792bcf8049313a3142496ce5fd9a9
go/types, types2: don't panic for invalid assignments of comma-ok expressions

The relevant code was broken with CL 478218. Before that CL,
Checker.assignVar used to return the assigned type, or nil,
in case of failure. Checker.recordCommaOkTypes used to take
two types (not two operands), and if one of those types was
nil, it would simply not record. CL 478218, lost that (nil)
signal.

This change consistently reports an assignment check failure
by setting x.mode to invalid for initVar and assignVar and
then tests if x.mode != invalid before recording a comma-ok
expression.

Fixes #59371.

Change-Id: I193815ff3e4b43e3e510fe25bd0e72e0a6a816c6
Reviewed-on: https://go-review.googlesource.com/c/go/+/486135
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
src/cmd/compile/internal/types2/assignments.go
src/go/types/assignments.go
src/internal/types/testdata/fixedbugs/issue59371.go [new file with mode: 0644]