]> Cypherpunks repositories - gostls13.git/commit
go/parser, go/types: don't parse type parameters on methods
authorRobert Findley <rfindley@google.com>
Wed, 2 Feb 2022 23:40:27 +0000 (18:40 -0500)
committerRobert Findley <rfindley@google.com>
Fri, 4 Feb 2022 00:43:57 +0000 (00:43 +0000)
commit4afcc9f35e97b4e96f2f350f2a00ea65f43f4175
tree2a2b65d1e361ce98acfcdf6e5b84e845cc3e41da
parent4e2410617d7b13e63e80ad77c9b2d44abaf39e9a
go/parser, go/types: don't parse type parameters on methods

The go/parser package is updated to report an error on method type
parameters, and to not store them in the AST. Tests are updated
accordingly, and error messages are normalized accross go/parser and the
compiler syntax package.

Before this CL, go/parser would parse type parameters on method
declarations and interface methods, leaving it to go/types to complain.
There are several problems with this:

- Interface Methods and Method declarations do not have type parameters
  in the spec. We try to align the parser with the productions in the
  spec.
- Parsing method type parameters means that downstream libraries
  (go/doc, go/format, etc.) theoretically need to handle them, even
  though they are not part of the language.
- Relatedly, go/types has inconsistent handling of method type
  parameters due to support being removed, leading to the crasher in
  #50427.

It is more consistent and safer to disallow type parameters on methods
in the parser.

Fixes #50427

Change-Id: I555766da0c76c4cf1cfe0baa9416863088088b4e
Reviewed-on: https://go-review.googlesource.com/c/go/+/382538
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
src/go/parser/parser.go
src/go/parser/short_test.go
src/go/parser/testdata/issue50427.go2 [new file with mode: 0644]
src/go/types/errorcodes.go
src/go/types/testdata/check/typeparams.go2
src/go/types/testdata/fixedbugs/issue39634.go2
src/go/types/testdata/fixedbugs/issue50427.go2 [new file with mode: 0644]