]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: don't attempt to generate wrappers for blank interface methods
authorAnthony Martin <ality@pbrane.org>
Mon, 19 Aug 2013 01:53:34 +0000 (11:53 +1000)
committerRob Pike <r@golang.org>
Mon, 19 Aug 2013 01:53:34 +0000 (11:53 +1000)
Fixes #5691.

R=golang-dev, bradfitz, daniel.morsing, rsc
CC=golang-dev
https://golang.org/cl/10255047

src/cmd/gc/reflect.c
test/interface/explicit.go
test/interface/fail.go

index 9f5f80b2811cae26670b1a8197140afd9affb81f..fc928864e8c81e404ce6e036d56bd2dc492432d6 100644 (file)
@@ -265,8 +265,8 @@ imethods(Type *t)
                last = a;
 
                // Compiler can only refer to wrappers for
-               // named interface types.
-               if(t->sym == S)
+               // named interface types and non-blank methods.
+               if(t->sym == S || isblanksym(method))
                        continue;
 
                // NOTE(rsc): Perhaps an oversight that
index eb81156e081d79ac08f966a423b28cc7313a6c31..36fa1a4224f9d329981390c5ba11d1aa6448d55e 100644 (file)
@@ -80,3 +80,22 @@ var m2 M = jj // ERROR "incompatible|wrong type for M method"
 
 var m3 = M(ii) // ERROR "invalid|missing"
 var m4 = M(jj) // ERROR "invalid|wrong type for M method"
+
+
+type B1 interface {
+       _()
+}
+
+type B2 interface {
+       M()
+       _()
+}
+
+type T2 struct{}
+
+func (t *T2) M() {}
+func (t *T2) _() {}
+
+// Check that nothing satisfies an interface with blank methods.
+var b1 B1 = &T2{} // ERROR "incompatible|missing _ method"
+var b2 B2 = &T2{} // ERROR "incompatible|missing _ method"
index 72b854dc00c753dcd8639f4186813837883f4a9f..81eb6cb3c151958b9193526c5e25f5941ef4cb42 100644 (file)
@@ -14,18 +14,33 @@ type I interface {
 
 func main() {
        shouldPanic(p1)
+       shouldPanic(p2)
 }
 
 func p1() {
        var s *S
        var i I
-       var e interface {}
+       var e interface{}
        e = s
        i = e.(I)
        _ = i
 }
 
-type S struct {
+type S struct{}
+
+func (s *S) _() {}
+
+type B interface {
+       _()
+}
+
+func p2() {
+       var s *S
+       var b B
+       var e interface{}
+       e = s
+       b = e.(B)
+       _ = b
 }
 
 func shouldPanic(f func()) {