Fixes #23116.
Change-Id: I5db5c5c39bbb50148ffa18c9393b045f255f80a3
Reviewed-on: https://go-review.googlesource.com/100459
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
if t != nil && !t.IsInterface() {
yyerrorl(n.Pos, "cannot type switch on non-interface value %L", n.Left.Right)
}
+ if v := n.Left.Left; v != nil && !isblank(v) && n.List.Len() == 0 {
+ // We don't actually declare the type switch's guarded
+ // declaration itself. So if there are no cases, we
+ // won't notice that it went unused.
+ yyerrorl(v.Pos, "%v declared and not used", v.Sym)
+ }
} else {
// expression switch
top = Erv
--- /dev/null
+// errorcheck
+
+// Copyright 2018 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.(type) {
+ }
+
+ switch t := x.(type) { // ERROR "declared and not used"
+ }
+}