go: syntax: parser doesn't recognize valid type parameter list

There is a (known) ambiguity for type parameter lists. For

type T[P *int] struct{}

the parser cannot tell if this is a generic type declaration or an array type declaration with length P*int. In general, people will write ~*int and there is the work-around interface{*int}; one just has to be aware of it.

But the parser also assumes that

type T[P *int, Q any] struct{}

is starting an array type declaration, yet this is clearly a valid type parameter list.

Should be fixed for 1.18 but is not a release blocker as there are work-arounds.

cc: @findleyr @ianlancetaylor

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks to @mdempsky’s help, we landed the fix to make go/parser and go/printer consistent with the compiler. Moved this to 1.19, when we can consider further improvements to our parsing of ambiguous type parameter lists.

CC @golang/release @mdempsky

As mentioned above, I think this may be a release blocker. Since the CL is mailed, I have added the release-blocker label in hopes that it can get merged before the RC1. Please reach out to me if any concerns.