2018-01-24 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / go.test / test / switch3.go
blob28705e464ef2c20949e7298fe1072a24fe2ab2df
1 // errorcheck
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.
7 // Verify that erroneous switch statements are detected by the compiler.
8 // Does not compile.
10 package main
12 type I interface {
13 M()
16 func bad() {
17 var i I
18 var s string
20 switch i {
21 case s: // ERROR "mismatched types string and I|incompatible types"
24 switch s {
25 case i: // ERROR "mismatched types I and string|incompatible types"
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:
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:
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:
49 var ar, ar1 [4]func()
50 switch ar { // ERROR "cannot switch on"
51 case ar1:
52 default:
55 var st, st1 struct{ f func() }
56 switch st { // ERROR "cannot switch on"
57 case st1:
61 func good() {
62 var i interface{}
63 var s string
65 switch i {
66 case s:
69 switch s {
70 case i: