]> Cypherpunks.ru repositories - gostls13.git/blob - test/switch6.go
cmd/compile: set correct line number for multiple defaults in switch error
[gostls13.git] / test / switch6.go
1 // errorcheck
2
3 // Copyright 2016 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 // Check the compiler's switch handling that happens
8 // at typechecking time.
9 // This must be separate from other checks,
10 // because errors during typechecking
11 // prevent other errors from being discovered.
12
13 package main
14
15 // Verify that type switch statements with impossible cases are detected by the compiler.
16 func f0(e error) {
17         switch e.(type) {
18         case int: // ERROR "impossible type switch case: e \(type error\) cannot have dynamic type int \(missing Error method\)"
19         }
20 }
21
22 // Verify that the compiler rejects multiple default cases.
23 func f1(e interface{}) {
24         switch e {
25         default:
26         default: // ERROR "multiple defaults in switch"
27         }
28         switch e.(type) {
29         default:
30         default: // ERROR "multiple defaults in switch"
31         }
32 }