]> Cypherpunks.ru repositories - gostls13.git/commit
go/parser: return ast.BadExpr for missing index operands
authorRob Findley <rfindley@google.com>
Mon, 22 Feb 2021 20:39:00 +0000 (15:39 -0500)
committerRobert Findley <rfindley@google.com>
Mon, 22 Feb 2021 23:43:15 +0000 (23:43 +0000)
commit1126bbb82ab2f81dcb33df696a1bb601a98d3174
tree80a070e56cc6f320d686afcadda69ea01b686268
parent1678829d9555761c0fa6571fd3bcaec016add3d2
go/parser: return ast.BadExpr for missing index operands

The parser was returning the indexed operand when a slice or index or
instance expression was missing any index arguments (as in the
expression `a[]`). This can result in returning an *ast.Ident for the
LHS of the (invalid) assignment `a[] = ...` -- in this case parsing the
LHS as just `a`. Unfortunately, as the indexed operand `a` has already
been resolved, this results in a panic for duplicate resolution.

Fix this by instead returning an ast.BadExpr. This can suppress some
subsequent errors from the typechecker, but those errors may or may not
be correct anyway. Other interpretations, such as an *ast.IndexExpr with
bad or missing X, run into potential misinterpretations downstream (both
caused errors in go/types and/or gopls).

Fixes #44504

Change-Id: I5ca8bed4a1861bcc7db8898770b08937110981d4
Reviewed-on: https://go-review.googlesource.com/c/go/+/295151
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/parser/parser.go
src/go/parser/testdata/issue44504.src [new file with mode: 0644]
src/go/types/fixedbugs/issue39634.go2