From db4dad7fd7f8d95ffb0c8e07de150015172d5853 Mon Sep 17 00:00:00 2001 From: Chris Manghane Date: Wed, 15 Oct 2014 09:55:13 -0700 Subject: [PATCH] cmd/gc: blank methods are not permitted in interface types Fixes #6606. LGTM=rsc R=rsc CC=golang-codereviews, gri https://golang.org/cl/156210044 --- src/cmd/gc/dcl.c | 3 +++ test/interface/explicit.go | 4 ++-- test/interface/fail.go | 14 -------------- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/cmd/gc/dcl.c b/src/cmd/gc/dcl.c index cc010d901c..dfcf47520a 100644 --- a/src/cmd/gc/dcl.c +++ b/src/cmd/gc/dcl.c @@ -558,6 +558,9 @@ ifacedcl(Node *n) if(n->op != ODCLFIELD || n->right == N) fatal("ifacedcl"); + if(isblank(n->left)) + yyerror("methods must have a unique non-blank name"); + dclcontext = PPARAM; markdcl(); funcdepth++; diff --git a/test/interface/explicit.go b/test/interface/explicit.go index 36fa1a4224..b10d02f248 100644 --- a/test/interface/explicit.go +++ b/test/interface/explicit.go @@ -83,12 +83,12 @@ var m4 = M(jj) // ERROR "invalid|wrong type for M method" type B1 interface { - _() + _() // ERROR "methods must have a unique non-blank name" } type B2 interface { M() - _() + _() // ERROR "methods must have a unique non-blank name" } type T2 struct{} diff --git a/test/interface/fail.go b/test/interface/fail.go index 81eb6cb3c1..d40a151383 100644 --- a/test/interface/fail.go +++ b/test/interface/fail.go @@ -14,7 +14,6 @@ type I interface { func main() { shouldPanic(p1) - shouldPanic(p2) } func p1() { @@ -30,19 +29,6 @@ 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()) { defer func() { if recover() == nil {