]> Cypherpunks repositories - gostls13.git/commit
cmd/compile/internal/syntax: accept all valid type parameter lists
authorRobert Griesemer <gri@golang.org>
Thu, 21 Apr 2022 05:19:49 +0000 (22:19 -0700)
committerRobert Griesemer <gri@golang.org>
Tue, 3 May 2022 14:51:51 +0000 (14:51 +0000)
commit920b9ab57dc6be573e8da705f13cf17ebab65342
tree11b807db5976b5ab6f6c7a82b305cb4cd959b963
parent3e00bd0ae4482064aa9eac0695078b1096ee913a
cmd/compile/internal/syntax: accept all valid type parameter lists

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 #49482.

Change-Id: I269b6291999bf60dc697d33d24a5635f01e065b9
Reviewed-on: https://go-review.googlesource.com/c/go/+/402256
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/compile/internal/syntax/parser.go
src/cmd/compile/internal/syntax/printer.go
src/cmd/compile/internal/syntax/printer_test.go
src/cmd/compile/internal/syntax/testdata/tparams.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue49482.go