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, go/parser: cannot parse certain constraint literals in generic types #49175

Closed
griesemer opened this issue Oct 27, 2021 · 4 comments
Closed
Labels
NeedsFix release-blocker
Milestone

Comments

@griesemer
Copy link
Contributor

@griesemer griesemer commented Oct 27, 2021

The following generic type declaration cannot be parsed:

package p
type _[_ []t]t // syntax error: unexpected ], expecting operand

Not a release blocker because the typical

type _[_ ~[]t]t

is accepted.

See also #49174 .

@griesemer griesemer added the NeedsFix label Oct 27, 2021
@griesemer griesemer added this to the Go1.18 milestone Oct 27, 2021
@griesemer griesemer self-assigned this Oct 27, 2021
@findleyr
Copy link
Contributor

@findleyr findleyr commented Oct 27, 2021

This affects go/parser as well.

@findleyr findleyr changed the title cmd/compile: cannot parse certain constraint literals in generic types cmd/compile, go/parser: cannot parse certain constraint literals in generic types Oct 27, 2021
@findleyr
Copy link
Contributor

@findleyr findleyr commented Oct 27, 2021

Another case:

type _[_ [1]t]t

@gopherbot
Copy link

@gopherbot gopherbot commented Oct 27, 2021

Change https://golang.org/cl/359134 mentions this issue: go/parser: fix parsing of array or slice constraint types

gopherbot pushed a commit that referenced this issue Oct 28, 2021
Now that we allow eliding 'interface' from constraint types, we need to
be a bit more careful about not consuming a '[' when parsing the next
expression after "type T [". We want to check if the next expression is
an identifier not followed by ']', in which case we're in a generic
type, but need to avoid parsing index or slice expressions. Such
expressions aren't valid array lengths because these expressions are
never constant, so when encountering a following '[' we can instead
assume that this is a type parameter field with array or slice type
constraint.

Test cases are added for the related issues #49174 and #49175, along
with a flag to enable tracing error tests.

For #49174
For #49175

Change-Id: I0476ef20c4c134ac537118272f20caaf123ee70e
Reviewed-on: https://go-review.googlesource.com/c/go/+/359134
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
@gopherbot
Copy link

@gopherbot gopherbot commented Oct 30, 2021

Change https://golang.org/cl/360135 mentions this issue: cmd/compile/internal/syntax: fix parsing of array or slice constraint types

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix release-blocker
Projects
None yet
Development

No branches or pull requests

3 participants