diff options
author | Rob Findley <rfindley@google.com> | 2021-06-21 16:10:14 -0400 |
---|---|---|
committer | Robert Findley <rfindley@google.com> | 2021-06-22 02:37:43 +0000 |
commit | 9afd158eb228fbe191ffa27b1a334a8837c45ef7 (patch) | |
tree | 3f7c561401a8d1f410fd1b5ced0418f4f79af01f /src/go/parser/parser.go | |
parent | 1bd5a20e3c8a3a82e87487c381b76c97b720cd52 (diff) | |
download | go-9afd158eb228fbe191ffa27b1a334a8837c45ef7.tar.gz go-9afd158eb228fbe191ffa27b1a334a8837c45ef7.zip |
go/parser: parse an ast.IndexExpr for a[]
To be consistent with Go 1.16, and to preserve as much information in
the AST as possible, parse an ast.IndexExpr with BadExpr Index for the
invalid expression a[].
A go/types test had to be adjusted to account for an additional error
resulting from this change.
We don't have a lot of test coverage for parser error recovery, so
rather than write an ad-hoc test for this issue, add a new go/types test
that checks that the indexed operand is used.
Updates #46403
Change-Id: I21e6ff4179746aaa50e530d4091fded450e69824
Reviewed-on: https://go-review.googlesource.com/c/go/+/329791
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.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/go/parser/parser.go b/src/go/parser/parser.go index 3965641713..f10c8650af 100644 --- a/src/go/parser/parser.go +++ b/src/go/parser/parser.go @@ -1302,7 +1302,12 @@ func (p *parser) parseIndexOrSliceOrInstance(x ast.Expr) ast.Expr { p.errorExpected(p.pos, "operand") rbrack := p.pos p.next() - return &ast.BadExpr{From: x.Pos(), To: rbrack} + return &ast.IndexExpr{ + X: x, + Lbrack: lbrack, + Index: &ast.BadExpr{From: rbrack, To: rbrack}, + Rbrack: rbrack, + } } p.exprLev++ |