]> Cypherpunks.ru repositories - gostls13.git/blob - test/switch3.go
test/[n-z]*.go: add documentation
[gostls13.git] / test / switch3.go
1 // errorcheck
2
3 // Copyright 2011 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 erroneous switch statements are detected by the compiler.
8 // Does not compile.
9
10 package main
11
12 type I interface {
13         M()
14 }
15
16 func bad() {
17         var i I
18         var s string
19
20         switch i {
21         case s: // ERROR "mismatched types string and I|incompatible types"
22         }
23
24         switch s {
25         case i: // ERROR "mismatched types I and string|incompatible types"
26         }
27
28         var m, m1 map[int]int
29         switch m {
30         case nil:
31         case m1: // ERROR "can only compare map m to nil|map can only be compared to nil"
32         default:
33         }
34
35         var a, a1 []int
36         switch a {
37         case nil:
38         case a1: // ERROR "can only compare slice a to nil|slice can only be compared to nil"
39         default:
40         }
41
42         var f, f1 func()
43         switch f {
44         case nil:
45         case f1: // ERROR "can only compare func f to nil|func can only be compared to nil"
46         default:
47         }
48 }
49
50 func good() {
51         var i interface{}
52         var s string
53
54         switch i {
55         case s:
56         }
57
58         switch s {
59         case i:
60         }
61 }