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

Comments

@griesemer
Copy link
Contributor

@griesemer griesemer commented Aug 25, 2021

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
Copy link
Contributor Author

@griesemer griesemer commented Aug 25, 2021

cc: @findleyr

Loading

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Aug 26, 2021

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.

Loading

@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

@gopherbot gopherbot commented Aug 26, 2021

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

Loading

@gopherbot gopherbot closed this in af80af2 Aug 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants