blob: 11b85d3692ceadd45f88a4cec72de436dd4aff0e [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 {
Matthew Dempsky70544c92016-06-06 17:59:05 -070014 case 0; // ERROR "expecting := or = or : or comma|expecting :"
Robert Griesemer7218b792015-11-19 15:43:05 -080015 }
16
17 switch {
Matthew Dempsky70544c92016-06-06 17:59:05 -070018 case 0; // ERROR "expecting := or = or : or comma|expecting :"
Robert Griesemer7218b792015-11-19 15:43:05 -080019 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}