| 1 |
// Package pkg ... |
| 2 |
package pkg |
| 3 |
|
| 4 |
func fn(x int) { |
| 5 |
switch x { |
| 6 |
} |
| 7 |
switch x { |
| 8 |
case 1: |
| 9 |
} |
| 10 |
|
| 11 |
switch x { |
| 12 |
case 1: |
| 13 |
case 2: |
| 14 |
case 3: |
| 15 |
} |
| 16 |
|
| 17 |
switch x { |
| 18 |
default: |
| 19 |
} |
| 20 |
|
| 21 |
switch x { |
| 22 |
default: |
| 23 |
case 1: |
| 24 |
} |
| 25 |
|
| 26 |
switch x { |
| 27 |
case 1: |
| 28 |
default: |
| 29 |
} |
| 30 |
|
| 31 |
switch x { |
| 32 |
case 1: |
| 33 |
default: //@ diag(`default case should be first or last in switch statement`) |
| 34 |
case 2: |
| 35 |
} |
| 36 |
|
| 37 |
// Don't flag either of these two; fallthrough is sensitive to the order of cases |
| 38 |
switch x { |
| 39 |
case 1: |
| 40 |
fallthrough |
| 41 |
default: |
| 42 |
case 2: |
| 43 |
} |
| 44 |
switch x { |
| 45 |
case 1: |
| 46 |
default: |
| 47 |
fallthrough |
| 48 |
case 2: |
| 49 |
} |
| 50 |
|
| 51 |
// Do flag these branches; don't get confused by the nested switch statements |
| 52 |
switch x { |
| 53 |
case 1: |
| 54 |
func() { |
| 55 |
switch x { |
| 56 |
case 1: |
| 57 |
fallthrough |
| 58 |
case 2: |
| 59 |
} |
| 60 |
}() |
| 61 |
default: //@ diag(`default case should be first or last in switch statement`) |
| 62 |
case 3: |
| 63 |
} |
| 64 |
|
| 65 |
switch x { |
| 66 |
case 1: |
| 67 |
switch x { |
| 68 |
case 1: |
| 69 |
fallthrough |
| 70 |
case 2: |
| 71 |
} |
| 72 |
default: //@ diag(`default case should be first or last in switch statement`) |
| 73 |
case 3: |
| 74 |
} |
| 75 |
|
| 76 |
// Fallthrough may be followed by empty statements |
| 77 |
switch x { |
| 78 |
case 1: |
| 79 |
fallthrough |
| 80 |
; |
| 81 |
default: |
| 82 |
case 3: |
| 83 |
} |
| 84 |
} |