aboutsummaryrefslogtreecommitdiff
path: root/src/go/parser/parser.go
diff options
context:
space:
mode:
authorRob Findley <rfindley@google.com>2021-04-30 16:58:56 -0400
committerRobert Findley <rfindley@google.com>2021-05-05 20:58:39 +0000
commitcf73f1a8e40f44c0d3c69d63a5815861d685a845 (patch)
tree02814ec693dd01cac3fdad5502ae0f831b43cd28 /src/go/parser/parser.go
parent15557af207f67e30a90977c5882e83103df54d49 (diff)
downloadgo-cf73f1a8e40f44c0d3c69d63a5815861d685a845.tar.gz
go-cf73f1a8e40f44c0d3c69d63a5815861d685a845.zip
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>
Diffstat (limited to 'src/go/parser/parser.go')
-rw-r--r--src/go/parser/parser.go1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/go/parser/parser.go b/src/go/parser/parser.go
index 36a044e3a2..3965641713 100644
--- a/src/go/parser/parser.go
+++ b/src/go/parser/parser.go
@@ -1095,6 +1095,7 @@ func (p *parser) parseChanType() *ast.ChanType {
}
func (p *parser) parseTypeInstance(typ ast.Expr) ast.Expr {
+ assert(p.parseTypeParams(), "parseTypeInstance while not parsing type params")
if p.trace {
defer un(trace(p, "TypeInstance"))
}