You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You get the following compilation error: cannot define new methods on non-local type.
I looked in the language specification, and I couldn't find any rule regarding where you can't define a method. I was wondering if it's something worth documenting in the spec. Thanks!
p.s. Shouldn't the error message be "cannot define new methods on a non-local type"?
The text was updated successfully, but these errors were encountered:
The spec is clear about this: "The type denoted by T is called the receiver base type; it must not be a pointer or interface type and it must be defined in the same package as the method."
(https://golang.org/ref/spec#Method_declarations)
This is working as intended.
PS: The error message could say "on a non-local type" but what we have is fine and its somewhat customary to be shorter in error messages than in usual prose.
If you write the following method:
You get the following compilation error:
cannot define new methods on non-local type
.I looked in the language specification, and I couldn't find any rule regarding where you can't define a method. I was wondering if it's something worth documenting in the spec. Thanks!
p.s. Shouldn't the error message be "cannot define new methods on a non-local type"?
The text was updated successfully, but these errors were encountered: