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.
7 // Verify that switch statements with duplicate cases are detected by the compiler.
15 case 0: // ERROR "duplicate case (0 in switch)?"
20 case int(0): // ERROR "duplicate case (int.0. .value 0. in switch)?"
27 case 5: // ERROR "duplicate case (5 in switch)?"
28 case 5.0: // ERROR "duplicate case (5 in switch)?"
35 case "": // ERROR "duplicate case (.. in switch)?"
37 case "abc": // ERROR "duplicate case (.abc. in switch)?"
41 func f3(e interface{}) {
44 case 0: // ERROR "duplicate case (0 in switch)?"
47 case float32(10): // ERROR "duplicate case (float32\(10\) .value 10. in switch)?"
49 case float64(10): // ERROR "duplicate case (float64\(10\) .value 10. in switch)?"
56 case [1]int{0}: // OK -- see issue 15896
60 // Ensure duplicate const bool clauses are accepted.
65 case 1 == 1: // Intentionally OK, even though a duplicate of the above const true
71 // Ensure duplicates in ranges are detected (issue #17517).
75 case 0, 1: // ERROR "duplicate case 0"
76 case 1, 2, 3, 4: // ERROR "duplicate case 1"
80 // Ensure duplicates with simple literals are printed as they were
81 // written, not just their values. Particularly useful for runes.
85 case 33, 33: // ERROR "duplicate case (33 in switch)?"
86 case 34, '"': // ERROR "duplicate case '"' .value 34. in switch"
87 case 35, rune('#'): // ERROR "duplicate case (rune.'#'. .value 35. in switch)?"
88 case 36, rune(36): // ERROR "duplicate case (rune.36. .value 36. in switch)?"
89 case 37, '$'+1: // ERROR "duplicate case ('\$' \+ 1 .value 37. in switch)?"
91 case 'a', 'b', 'c', 'd': // ERROR "duplicate case ('b' .value 98.)?"
92 case x, x: // ERROR "duplicate case (x .value 10.)?"