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, types2: type parameter type string is misleading #49215

Closed
findleyr opened this issue Oct 29, 2021 · 3 comments
Closed

go/types, types2: type parameter type string is misleading #49215

findleyr opened this issue Oct 29, 2021 · 3 comments
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. release-blocker
Milestone

Comments

@findleyr
Copy link
Contributor

As we focus on error messages, both in the type checker and in vet, I am becoming increasingly concerned that the type parameter type string is misleading.

For example, when running vet on the following code

package pkg

type U[P any] int

func (r U[P]) GobDecode(P) {}

We end up with diagnostics like this:

method GobDecode(pkg.P) should have signature GobDecode([]byte) error

In these cases the qualification of pkg.P is almost always misleading -- it looks like a named type.

I can think of several ways to proceed:

  1. Do nothing.
  2. Drop qualification altogether: a type parameter type string is just its name: GobDecode(P)
  3. Capture the 'owning' object when binding a type parameter to a type: GobDecode(pkg.U.GobDecode.P) (assuming we associate with the method).
  4. Use a special prefix or suffix to identify that something is a type parameter: GobDecode($P) (this is like (2) but unambiguous when using e.g. types.RelativeTo as a qualifier).

Type parameters only have meaning in the scope in which they are bound. For that reason, maybe it's sufficient for their type string to just be their name, as in option (2). Option 3 is precise, but verbose. I like the look of option 4, but it is rather risky.

CC @griesemer @mdempsky

@findleyr findleyr added this to the Go1.18 milestone Oct 29, 2021
@findleyr findleyr added release-blocker NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. labels Oct 29, 2021
@griesemer
Copy link
Contributor

I suggest option (2). Small is beautiful.

@gopherbot
Copy link

Change https://golang.org/cl/360938 mentions this issue: go/types: remove qualification from type parameter strings

@gopherbot
Copy link

Change https://golang.org/cl/361266 mentions this issue: cmd/compile/internal/types2: remove qualification from type parameter strings

gopherbot pushed a commit that referenced this issue Nov 4, 2021
… strings

This is a clean port of CL 360938 from go/types to types2.

For #49215.

Change-Id: If20779c862b71641cb6afe4c281fbad5488a8abe
Reviewed-on: https://go-review.googlesource.com/c/go/+/361266
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
@golang golang locked and limited conversation to collaborators Nov 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. release-blocker
Projects
None yet
Development

No branches or pull requests

3 participants