Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
griesemer opened this issue Oct 30, 2023 · 4 comments
Open
Labels
gopls/parsing Issues related to parsing / poor parser recovery. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@griesemer
Copy link
Contributor

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

@griesemer griesemer added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 30, 2023
@griesemer griesemer added this to the Backlog milestone Oct 30, 2023
@griesemer
Copy link
Contributor Author

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).

@lucasgpulcinelli
Copy link

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

@griesemer
Copy link
Contributor Author

@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.

@findleyr findleyr added the gopls/parsing Issues related to parsing / poor parser recovery. label Nov 17, 2023
@gopherbot
Copy link
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
Labels
gopls/parsing Issues related to parsing / poor parser recovery. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants