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
In Go1.9, with type alias support (currently on dev.typealias branch):
type T struct{}
type A = T
func (T) m() {}
func (A) m() {} // <<<< this should be an error
func (A) m() {} // error reported here
compiles without reporting an error for the first method A.m.
The underlying problem is that the gc compiler simply throws in all method declarations into the package "scope" with artificial names T.m, (*T).m, A.m, so (at least during the declaration phase) T.m and A.m have different names and won't lead to a redeclaration error (see dcl.go, func methodname0). The second A.m declaration leads to an error because it conflicts with the first one.
This also applies to redeclaration of a method m once on a T receiver and once on a *T receiver; however that redeclaration is caught later (see dcl.go, func addmethod).
We need to do something similar for methods declared on receivers that are type aliases.
Independent of aliases, it's odd that some method redeclarations are detected during node construction while others are detected later (with different error messages).
The text was updated successfully, but these errors were encountered:
In Go1.9, with type alias support (currently on dev.typealias branch):
compiles without reporting an error for the first method
A.m
.The underlying problem is that the gc compiler simply throws in all method declarations into the package "scope" with artificial names
T.m
,(*T).m
,A.m
, so (at least during the declaration phase)T.m
andA.m
have different names and won't lead to a redeclaration error (see dcl.go, func methodname0). The secondA.m
declaration leads to an error because it conflicts with the first one.This also applies to redeclaration of a method
m
once on aT
receiver and once on a*T
receiver; however that redeclaration is caught later (see dcl.go, func addmethod).We need to do something similar for methods declared on receivers that are type aliases.
Independent of aliases, it's odd that some method redeclarations are detected during node construction while others are detected later (with different error messages).
The text was updated successfully, but these errors were encountered: