mirror of
https://github.com/golang/go
synced 2024-09-06 00:19:45 +00:00
cmd/gc: typecheck type switch variables
Type switch variables was not typechecked. Previously it lead only to a minor consequence: switch unsafe.Sizeof = x.(type) { generated an inconsistent error message. But capturing by value functionality now requries typechecking of all ONAMEs. Fixes #9731 Change-Id: If037883cba53d85028fb97b1328696091b3b7ddd Reviewed-on: https://go-review.googlesource.com/3600 Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
c9321f3fb1
commit
8e2423a67d
|
@ -939,6 +939,8 @@ typecheckswitch(Node *n)
|
|||
// multiple entry type switch or default
|
||||
nvar->ntype = typenod(n->type);
|
||||
}
|
||||
typecheck(&nvar, Erv | Easgn);
|
||||
ncase->nname = nvar;
|
||||
}
|
||||
}
|
||||
typechecklist(ncase->nbody, Etop);
|
||||
|
|
21
test/fixedbugs/issue9731.go
Normal file
21
test/fixedbugs/issue9731.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
// compile
|
||||
|
||||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
func f(x interface{}) {
|
||||
switch x := x.(type) {
|
||||
case int:
|
||||
func() {
|
||||
_ = x
|
||||
}()
|
||||
case map[int]int:
|
||||
func() {
|
||||
for range x {
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue