// Verify that type switch statements with impossible cases are detected by the compiler.
func f0(e error) {
switch e.(type) {
- case int: // ERROR "impossible type switch case: e \(type error\) cannot have dynamic type int \(missing Error method\)"
+ case int: // ERROR "impossible type switch case: (int\n\t)?e \(.*type error\) cannot have dynamic type int \(missing method Error\)"
}
}
// Verify that the compiler rejects multiple default cases.
func f1(e interface{}) {
- switch e { // ERROR "multiple defaults in switch"
- default:
+ switch e {
default:
+ default: // ERROR "multiple defaults( in switch)?"
}
- switch e.(type) { // ERROR "multiple defaults in switch"
- default:
+ switch e.(type) {
default:
+ default: // ERROR "multiple defaults( in switch)?"
+ }
+}
+
+type I interface {
+ Foo()
+}
+
+type X int
+
+func (*X) Foo() {}
+func f2() {
+ var i I
+ switch i.(type) {
+ case X: // ERROR "impossible type switch case: (X\n\t)?i \(.*type I\) cannot have dynamic type X \(method Foo has pointer receiver\)"
}
}