Skip to content

go/parser: poor error recovery after missing function call argument #58833

Open
@adonovan

Description

@adonovan

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.

Screenshot 2023-03-02 at 1 06 40 PM

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.gopls/parsingIssues related to parsing / poor parser recovery.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions