Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: invalid duplicate method decl. accepted if receiver type is alias #18655

Closed
griesemer opened this issue Jan 13, 2017 · 1 comment
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@griesemer
Copy link
Contributor

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).

@griesemer griesemer added the NeedsFix The path to resolution is known, but the work has not been done. label Jan 13, 2017
@griesemer griesemer added this to the Go1.9Early milestone Jan 13, 2017
@griesemer griesemer self-assigned this Jan 13, 2017
@mdempsky mdempsky self-assigned this Jan 23, 2017
@gopherbot
Copy link

CL https://golang.org/cl/35575 mentions this issue.

@golang golang locked and limited conversation to collaborators Jan 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants