Debian Codegraph @

test/typeswitch2b.go

raw
1 // errorcheck
2
3 // Copyright 2019 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
6
7 // Verify that various erroneous type switches are caught by the compiler.
8 // Does not compile.
9
10 package main
11
12 func notused(x interface{}) {
13 // The first t is in a different scope than the 2nd t; it cannot
14 // be accessed (=> declared and not used error); but it is legal
15 // to declare it.
16 switch t := 0; t := x.(type) { // ERROR "declared and not used"
17 case int:
18 _ = t // this is using the t of "t := x.(type)"
19 }
20 }