]> Cypherpunks repositories - gostls13.git/commit
cmd/vet: avoid internal error for implicitly declared type switch vars
authorRobert Griesemer <gri@golang.org>
Thu, 13 Sep 2018 01:07:51 +0000 (18:07 -0700)
committerRobert Griesemer <gri@golang.org>
Thu, 13 Sep 2018 15:25:25 +0000 (15:25 +0000)
commit77e503a3224ada21cc84ab9078980a7d4230492a
tree133c64a18f1c19cf2c70792330f49d6340cc5c5a
parent8149db4f64aa72407d8be2184d0b414b535cd124
cmd/vet: avoid internal error for implicitly declared type switch vars

For type switches using a short variable declaration of the form

   switch t := x.(type) {
   case T1:
   ...

go/types doesn't declare the symbolic variable (t in this example)
with the switch; thus such variables are not found in types.Info.Defs.

Instead they are implicitly declared with each type switch case,
and can be found in types.Info.Implicits.

Adjust the shadowing code accordingly.

Added a test case to verify that the issue is fixed, and a test
case verifying that the shadowing code now considers implicitly
declared variables introduces in type switch cases.

While at it, also fixed the (internal) error reporting to provide
more accurate information.

Fixe #26725.

Change-Id: If408ed9e692bf47c640f81de8f46bf5eb43415b0
Reviewed-on: https://go-review.googlesource.com/135117
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Alan Donovan <adonovan@google.com>
src/cmd/vet/main.go
src/cmd/vet/shadow.go
src/cmd/vet/testdata/shadow.go
src/cmd/vet/types.go