Skip to content

go/parser: bad error recovery for simple program with missing function name #63834

Open

Description

@griesemer
package p

func (x string) []byte {
        return []byte(x)
}

produces (when run as test under go/types):

    check_test.go:168: testdata/manual.go:10:17: expected 'IDENT', found '['
    check_test.go:168: testdata/manual.go:10:18: expected '(', found ']'
    check_test.go:168: testdata/manual.go:10:24: missing ',' in parameter list
    check_test.go:168: testdata/manual.go:11:9: expected ')', found 'return'
    check_test.go:168: testdata/manual.go:11:17: missing ',' in parameter list
    check_test.go:168: testdata/manual.go:11:25: missing ',' before newline in parameter list
    check_test.go:168: testdata/manual.go:12:1: expected ')', found '}'
    check_test.go:168: testdata/manual.go:12:1: missing ',' in parameter list
    check_test.go:168: testdata/manual.go:12:2: expected ')', found 'EOF'
    check_test.go:168: testdata/manual.go:12:2: expected ')', found newline
    check_test.go:168: testdata/manual.go:12:2: expected ';', found 'EOF'
    check_test.go:168: testdata/manual.go:12:2: missing ',' before newline in parameter list

This may be easy to address.

cc: @findleyr

Activity

  1. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Oct 30, 2023
  2. added this to the Backlog milestone on Oct 30, 2023
  3. griesemer commented on Oct 30, 2023

    @griesemer
    ContributorAuthor

    For the reference, the syntax parser produces just one error (also run under types2 test harness):

        check_test.go:157: testdata/manual.go:10:17: syntax error: unexpected [, expected name
    

    (but then types2 crashes).

  4. lucasgpulcinelli commented on Nov 16, 2023

    @lucasgpulcinelli

    Hi, first time contributor here
    Is there someone working on this issue? It seems that the parseFuncDecl function in the go/parser package does not check syntax errors during function declaration if it does not conform to the usual two forms (methods and usual functions), and that is causing the cascade of errors seen.

    Me and some colleagues would be interested in solving this

  5. griesemer commented on Nov 16, 2023

    @griesemer
    ContributorAuthor

    @lucasgpulcinelli Nobody is working on this at the moment. Feel free to give it a shot. One word of caution, if I may: whatever your potential fix, please don't simply look for the particular pattern causing the problem here - it's an easy pitfall. As an aside, you might also want to look at cmd/compile/internal/syntax/parser.go which has better error recovery. Thanks.

  6. gopherbot commented on Nov 27, 2023

    @gopherbot
    Contributor

    Change https://go.dev/cl/545075 mentions this issue: go/parser: improve error detection while parsing functions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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