| 1 |
// 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 |
|
| 7 |
// Verify that erroneous switch statements are detected by the compiler. |
| 8 |
// Does not compile. |
| 9 |
|
| 10 |
package main |
| 11 |
|
| 12 |
func f() { |
| 13 |
switch { |
| 14 |
case 0; // ERROR "expecting := or = or : or comma|expected :" |
| 15 |
} |
| 16 |
|
| 17 |
switch { |
| 18 |
case 0; // ERROR "expecting := or = or : or comma|expected :" |
| 19 |
default: |
| 20 |
} |
| 21 |
|
| 22 |
switch { |
| 23 |
case 0: case 0: default: |
| 24 |
} |
| 25 |
|
| 26 |
switch { |
| 27 |
case 0: f(); case 0: |
| 28 |
case 0: f() case 0: // ERROR "unexpected keyword case at end of statement" |
| 29 |
} |
| 30 |
|
| 31 |
switch { |
| 32 |
case 0: f(); default: |
| 33 |
case 0: f() default: // ERROR "unexpected keyword default at end of statement" |
| 34 |
} |
| 35 |
|
| 36 |
switch { |
| 37 |
if x: // ERROR "expected case or default or }" |
| 38 |
} |
| 39 |
} |