Move test for isblank into addmethod so that most of the type checking
for methods is also performed for blank methods.
Fixes #11366.
Change-Id: I13d554723bf96d906d0b3ff390d7b7c87c1a5020
Reviewed-on: https://go-review.googlesource.com/16866
Reviewed-by: Robert Griesemer <gri@golang.org>
}
pa = f
+ if local && !pa.Local {
+ Yyerror("cannot define new methods on non-local type %v", pa)
+ return
+ }
+
+ if isblanksym(sf) {
+ return
+ }
+
if pa.Etype == TSTRUCT {
for f := pa.Type; f != nil; f = f.Down {
if f.Sym == sf {
}
}
- if local && !pa.Local {
- // defining method on non-local type.
- Yyerror("cannot define new methods on non-local type %v", pa)
-
- return
- }
-
n := Nod(ODCLFIELD, newname(sf), nil)
n.Type = t
n.Type = t
t.Nname = n.Func.Nname
rcvr := getthisx(t).Type
- if rcvr != nil && n.Func.Shortname != nil && !isblank(n.Func.Shortname) {
+ if rcvr != nil && n.Func.Shortname != nil {
addmethod(n.Func.Shortname.Sym, t, true, n.Func.Nname.Nointerface)
}
_ int
}
+func (x int) _() { // ERROR "cannot define new methods on non-local type"
+ println(x)
+}
+
type T struct {
_ []int
}