blob: 11ff5c5d9b95c275e81ff965245a71b9e1d5e19d [file] [log] [blame]
Robert Griesemer7218b792015-11-19 15:43:05 -08001// errorcheck
2
3// Copyright 2015 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
Robert Griesemeraad18b82015-11-20 16:49:30 -08007// Verify that erroneous switch statements are detected by the compiler.
8// Does not compile.
Robert Griesemer7218b792015-11-19 15:43:05 -08009
10package main
11
Robert Griesemeraad18b82015-11-20 16:49:30 -080012func f() {
Robert Griesemer7218b792015-11-19 15:43:05 -080013 switch {
14 case 0; // ERROR "expecting := or = or : or comma"
15 }
16
17 switch {
18 case 0; // ERROR "expecting := or = or : or comma"
19 default:
20 }
21
22 switch {
Robert Griesemeraad18b82015-11-20 16:49:30 -080023 case 0: case 0: default:
24 }
25
26 switch {
27 case 0: f(); case 0:
28 case 0: f() case 0: // ERROR "unexpected case at end of statement"
29 }
30
31 switch {
32 case 0: f(); default:
33 case 0: f() default: // ERROR "unexpected default at end of statement"
34 }
35
36 switch {
Robert Griesemer7218b792015-11-19 15:43:05 -080037 if x: // ERROR "expecting case or default or }"
38 }
39}