]> Cypherpunks repositories - gostls13.git/commit
go/parser: accept all valid type parameter lists
authorRobert Griesemer <gri@golang.org>
Tue, 3 May 2022 17:42:22 +0000 (10:42 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 4 May 2022 20:20:27 +0000 (20:20 +0000)
commitab0bb52f2fdf454a2cbf20e95f5ecd2bd68b5ada
tree52b2d2b61446b2d53f28bcc4d186e5a795ae573b
parentfd6ef06296b55a234d4fd5ebf5dd3e5bfd8f4e25
go/parser: accept all valid type parameter lists

This is a port of CL 402256 from the syntax package to go/parser
with adjustments because of the different AST structure, and
excluding any necessary go/printer changes (separate CL).

Type parameter lists starting with the form [name *T|...] or
[name (X)|...] may look like an array length expression [x].
Only after parsing the entire initial expression and checking
whether the expression contains type elements or is followed
by a comma can we make the final decision.

This change simplifies the existing parsing strategy: instead
of trying to make an upfront decision with limited information
(which is insufficient), the parser now parses the start of a
type parameter list or array length specification as expression.
In a second step, if the expression can be split into a name
followed by a type element, or a name followed by an ordinary
expression which is succeeded by a comma, we assume a type
parameter list (because it can't be an array length).
In all other cases we assume an array length specification.

Fixes #52559.

Change-Id: I11ab6e62b073b78b2331bb6063cf74d2a9eaa236
Reviewed-on: https://go-review.googlesource.com/c/go/+/403937
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
src/go/parser/parser.go
src/go/parser/testdata/issue49482.go2
src/go/parser/testdata/tparams.go2 [new file with mode: 0644]
src/go/printer/testdata/generics.golden
src/go/types/testdata/fixedbugs/issue49482.go