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

go/types: method signatures not identical modulo receiver type parameter names #49912

Closed
findleyr opened this issue Dec 2, 2021 · 6 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@findleyr
Copy link
Contributor

findleyr commented Dec 2, 2021

Consider the following:

package p

// Basic defined types
type T1 struct{}
type T2 struct{}

// Identical methods
func (T1) M(int) {}
func (T2) M(int) {}

// Identical generic functions
func F1[P C](p P) {}
func F2[Q C](q Q) {}

// Generic types
type G1[P any] struct{}
type G2[Q any] struct{}

// Identical methods?
func (G1[P]) M(G1[P], G2[P]) {}
func (G2[P]) M(G1[P], G2[P]) {}

For the types in this code, the following holds (in pseudo go/types API):

  1. Identical(T1.Method(0).Type(), T2.Method(0).Type()) == true
  2. Identical(F1.Type(), F2.Type()) == true
  3. Identical(G1[int].Method(0).Type(), G2[int].Method(0).Type()) == true
  4. Identical(G1.Method(0).Type(), G2.Method(0).Type()) == false

(4) is false, because although we consider signatures identical modulo type parameter names, we don't consider methods identical modulo type parameter names. This may be minor, but seems incorrect.

@griesemer what do you think?

@findleyr findleyr added NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. release-blocker labels Dec 2, 2021
@findleyr findleyr added this to the Go1.18 milestone Dec 2, 2021
@findleyr findleyr added the okay-after-beta1 Used by release team to mark a release-blocker issue as okay to resolve either before or after beta1 label Dec 2, 2021
@findleyr
Copy link
Contributor Author

findleyr commented Dec 2, 2021

I'm tentatively marking this as okay-after-beta1. Making a decision here could technically constitute an API change, but it seems very obscure and unlikely to be a problem. Others may feel differently.

@griesemer griesemer changed the title go/types: can methods on different generic receivers be identical? go/types: method signatures not identical modulo receiver type parameter names Dec 2, 2021
@findleyr
Copy link
Contributor Author

findleyr commented Dec 2, 2021

@griesemer and I discussed the following:

  • It's actually a bit odd that we don't consider receiver in Identical, since the identity of a method is more naturally the identity of the method expression, not the method value.
  • But this behavior has existed for a while, and may be useful (for example, looking for completion candidates in the Method API).
  • Our current treatment of receiver type parameters is inconsistent with function type parameters.

So we concluded that we should be consistent and ignore the names of receiver type parameters the same way we ignore the names of function type parameters.

@findleyr findleyr added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. labels Dec 2, 2021
@findleyr findleyr self-assigned this Dec 2, 2021
@toothrot
Copy link
Contributor

toothrot commented Dec 8, 2021

Checking on this as a release blocker. Are there any updates?

@griesemer
Copy link
Contributor

I believe we know how to fix this but haven't gotten around to it. This is primarily and issue for tools and shouldn't affect the beta.

@cherrymui cherrymui removed the okay-after-beta1 Used by release team to mark a release-blocker issue as okay to resolve either before or after beta1 label Dec 14, 2021
@findleyr
Copy link
Contributor Author

Will address this by next week.

@findleyr
Copy link
Contributor Author

findleyr commented Feb 4, 2022

As discussed in #50887, we decided/discovered that the best course of action is to do nothing here, but to answer questions about method identity using instantiations with type parameters.

@findleyr findleyr closed this as completed Feb 4, 2022
@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 NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

5 participants