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

types2, go/types: declaring methods on instantiated types through an alias type should not be permitted #47968

Closed
griesemer opened this issue Aug 25, 2021 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Milestone

Comments

@griesemer
Copy link
Contributor

Reminder issue. The following code

package p

type T[P any] struct{}
type A = T[int]

func (A) m() {}

func _() {
	var a A
	a.m()
}

adds a method m to T[int] via the alias A. But the type T[int] never learns about this method. The correct fix depends on the outcome of #46477.

See also #46477 (comment).

@griesemer griesemer added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker labels Aug 25, 2021
@griesemer griesemer added this to the Go1.18 milestone Aug 25, 2021
@griesemer griesemer self-assigned this Aug 25, 2021
@griesemer
Copy link
Contributor Author

cc: @findleyr

@mdempsky
Copy link
Member

I think this is orthogonal to #46477 and an issue regardless. In general, we don't allow declaring new methods on instantiated types; e.g., func (T[*int]) m() {} is an error. I don't think type U = T[*int]; func (U) m() {} should behave differently.

@griesemer griesemer changed the title types2, go/types: associating methods with instantiated types through alias type is broken types2, go/types: declaring methods on instantiated types through alias type should not be permitted Aug 26, 2021
@griesemer griesemer changed the title types2, go/types: declaring methods on instantiated types through alias type should not be permitted types2, go/types: declaring methods on instantiated types through an alias type should not be permitted Aug 26, 2021
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/345472 mentions this issue: cmd/compile/internal/types2: do not declare new methods on instantiated types

@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Projects
None yet
Development

No branches or pull requests

3 participants