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/go2go: improve error messages for missing or superfluous type constraints #43527

candlerb opened this issue Jan 5, 2021 · 2 comments


Copy link

@candlerb candlerb commented Jan 5, 2021

What version of Go are you using (go version)?

go2go playground

Does this issue reproduce with the latest release?


What operating system and processor architecture are you using (go env)?


What did you do?


    func (m *MyMap[KT,VT comparable]) set(k KT, v VT) { ...

    func blah[T1, T2](x T1) T2 { ...

What did you expect to see?

  1. error to the effect that a constraint was used in a place where it's not allowed
  2. error to the effect that a type constraint is missing

What did you see instead?

  1. "missing ',' in type argument list"
  2. "all type parameters must be named" (even though they were named!)
@ianlancetaylor ianlancetaylor changed the title go2: improve error messages for missing or superfluous type constraints cmd/go2go: improve error messages for missing or superfluous type constraints Jan 5, 2021
@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Jan 5, 2021
Copy link

@ianlancetaylor ianlancetaylor commented Jan 5, 2021

@griesemer griesemer self-assigned this Jan 6, 2021
@griesemer griesemer modified the milestones: Unreleased, Go1.17 Jan 6, 2021
Copy link

@griesemer griesemer commented Jan 6, 2021

The first error is fixed in the latest (internal, not deployed version). The 2nd error is correct but misleading: Since the type parameter list is [T1, T2] and since type parameter lists are syntactically like regular parameter lists (but for the []'s), it looks like a parameter list with two constraints T1 and T2 and without explicitly named type parameters. For comparison, note that func f(int, int){} is a valid function declaration with unnamed value parameters.

Anyway, agreed that the error message should be better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.