aboutsummaryrefslogtreecommitdiff
path: root/go
diff options
context:
space:
mode:
Diffstat (limited to 'go')
-rw-r--r--go/types/stmt.go9
-rw-r--r--go/types/testdata/stmt0.src1
2 files changed, 9 insertions, 1 deletions
diff --git a/go/types/stmt.go b/go/types/stmt.go
index fa60f64..3917336 100644
--- a/go/types/stmt.go
+++ b/go/types/stmt.go
@@ -456,7 +456,14 @@ func (check *Checker) stmt(ctxt stmtContext, s ast.Stmt) {
check.invalidAST(s.Pos(), "incorrect form of type switch guard")
return
}
- check.recordDef(lhs, nil) // lhs variable is implicitly declared in each cause clause
+
+ if lhs.Name == "_" {
+ // _ := x.(type) is an invalid short variable declaration
+ check.softErrorf(lhs.Pos(), "no new variable on left side of :=")
+ lhs = nil // avoid declared but not used error below
+ } else {
+ check.recordDef(lhs, nil) // lhs variable is implicitly declared in each cause clause
+ }
rhs = guard.Rhs[0]
diff --git a/go/types/testdata/stmt0.src b/go/types/testdata/stmt0.src
index 4c84036..073e83b 100644
--- a/go/types/testdata/stmt0.src
+++ b/go/types/testdata/stmt0.src
@@ -540,6 +540,7 @@ func typeswitches() {
}
switch x /* ERROR "declared but not used" */ := x.(type) {}
+ switch _ /* ERROR "no new variable on left side of :=" */ := x.(type) {}
switch x := x.(type) {
case int: