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/compile: parser doesn't recognize valid type parameter list #49482

Open
griesemer opened this issue Nov 9, 2021 · 4 comments
Open

cmd/compile: parser doesn't recognize valid type parameter list #49482

griesemer opened this issue Nov 9, 2021 · 4 comments
Assignees
Labels
Milestone

Comments

@griesemer
Copy link
Contributor

@griesemer griesemer commented Nov 9, 2021

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

@griesemer griesemer added this to the Go1.18 milestone Nov 9, 2021
@griesemer griesemer self-assigned this Nov 9, 2021
@griesemer
Copy link
Contributor Author

@griesemer griesemer commented Nov 9, 2021

Another work-around for the single type-parameter case would be a trailing comma, as in

type T[P *int,] struct{}

because type parameter lists (like all parameter lists) permit a trailing comma, while array type declarations don't.

Loading

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Nov 9, 2021

I assume that this also works:

type T[P (*int)] struct{}

Loading

@griesemer
Copy link
Contributor Author

@griesemer griesemer commented Nov 9, 2021

It should but currently doesn't, it appears. Filed a separate issue #49485.

Loading

@griesemer
Copy link
Contributor Author

@griesemer griesemer commented Nov 10, 2021

Loading

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

Successfully merging a pull request may close this issue.

None yet
2 participants