]> Cypherpunks.ru repositories - gostls13.git/commit
go/parser: don't parse a nil IndexExpr.Index
authorRob Findley <rfindley@google.com>
Fri, 30 Apr 2021 20:58:56 +0000 (16:58 -0400)
committerRobert Findley <rfindley@google.com>
Wed, 5 May 2021 20:58:39 +0000 (20:58 +0000)
commitcf73f1a8e40f44c0d3c69d63a5815861d685a845
tree02814ec693dd01cac3fdad5502ae0f831b43cd28
parent15557af207f67e30a90977c5882e83103df54d49
go/parser: don't parse a nil IndexExpr.Index

When parsing type parameters, an empty type instantiation was parsed as
an IndexExpr with nil Index. This should be considered a breaking change
to parsing: ast.Walk previously assumed that Index was non-nil.

Back out the nil check in ast.Walk, and for now pack an empty argument
list as a non-nil ListExpr with nil Elems.

Alternatives considered:
 - Parsing the entire index expression as a BadExpr: this led to
   inferior errors while type checking.
 - Parsing the Index as a BadExpr: this seems reasonable, but encodes
   strictly less information into the AST.

We may want to opt for one of these alternatives in the future, but for
now let's just fix the breaking change.

Change-Id: I93f2b89641692ac014b8ee98bfa031ed3477afb8
Reviewed-on: https://go-review.googlesource.com/c/go/+/315851
Trust: Robert Findley <rfindley@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/ast/walk.go
src/go/internal/typeparams/notypeparams.go
src/go/internal/typeparams/typeparams.go
src/go/parser/parser.go