Description
This program contains a syntax error in Abs(,)
that causes the parser's recovery to generate a BadExpr for math.Lde
.
func g() {
math.Abs(,)
//
math.Lde()
}
This causes go/types not to recognize math
as a reference to a package, and causes completions in gopls to misbehave.
I think the parser could do a better job of recovery. @griesemer gives reasons why this is difficult in #24327 (comment):
go/parser is likely falling behind the compiler due to the compiler's parser (package syntax) being actively improved whenever we run into unsatisfying error messages. It's fairly time-consuming to back-port those fixes because the parsers don't have the same structure, and small local changes sometimes have unexpected consequences with respect to error handling (hence those changes, even if small, are time-consuming to get right).
Ideally, in the long run we should migrate to package syntax. Failing that, one option might be to replace go/parser with the syntax package parser while keeping the same API. That might be not too hard since the syntax trees are reasonably close.
Related issue of gopls completion after a syntax error: