aboutsummaryrefslogtreecommitdiff
path: root/test/switch6.go
diff options
context:
space:
mode:
authorEmmanuel Odeke <emm.odeke@gmail.com>2017-01-14 05:23:23 -0700
committerMatthew Dempsky <mdempsky@google.com>2017-02-02 17:36:43 +0000
commit34b563f447280f9d386f208646ac4f94cafc4ab6 (patch)
tree97434c6aa865f67c9979561b46d219c9e60705ac /test/switch6.go
parentba1a65fc518c367bd4a3e18324036d457e6a07c3 (diff)
downloadgo-34b563f447280f9d386f208646ac4f94cafc4ab6.tar.gz
go-34b563f447280f9d386f208646ac4f94cafc4ab6.zip
cmd/compile: improve error for wrong type in switch
Fixes #10561. Provides a better diagnostic message for failed type switch satisfaction in the case that a value receiver is being used in place of the pointer receiver that implements and satisfies the interface. Change-Id: If8c13ba13f2a8d81bf44bac7c3a66c12921ba921 Reviewed-on: https://go-review.googlesource.com/35235 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'test/switch6.go')
-rw-r--r--test/switch6.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/test/switch6.go b/test/switch6.go
index 32392d8f73..9d102fef51 100644
--- a/test/switch6.go
+++ b/test/switch6.go
@@ -30,3 +30,17 @@ func f1(e interface{}) {
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: i \(type I\) cannot have dynamic type X \(Foo method has pointer receiver\)"
+ }
+}