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

cmd/compile: confusing message for syntax error #56022

Closed
ianlancetaylor opened this issue Oct 4, 2022 · 4 comments
Closed

cmd/compile: confusing message for syntax error #56022

ianlancetaylor opened this issue Oct 4, 2022 · 4 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@ianlancetaylor
Copy link
Contributor

Bug mentioned by @apparentlymart in #55863.

With tip, compiling

package main

type Foo struct{}

func (f *Foo) (
	Blah() {}
)

produces the error messages

foo.go:5:15: syntax error: unexpected (, expected name or (
foo.go:6:9: syntax error: unexpected { after top level declaration

The first error makes no sense: it is saying that it found an unexpected left parenthesis when it expected a left parenthesis.

I think the error is in (*parser).funcDeclOrNil: it should not say that it expects a left parenthesis if it already found a receiver.

CC @griesemer

@ianlancetaylor ianlancetaylor added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 4, 2022
@ianlancetaylor ianlancetaylor added this to the Backlog milestone Oct 4, 2022
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Oct 4, 2022
@rittneje
Copy link

rittneje commented Oct 4, 2022

Strangely, gofmt yields the correct error message:

prog.go:5:15: expected 'IDENT', found '(' (and 1 more errors)

@ianlancetaylor
Copy link
Contributor Author

gofmt and the compiler do not use the same parser, so they can have different error messages.

@gopherbot
Copy link

Change https://go.dev/cl/437036 mentions this issue: cmd/compile: improve message for syntax error in "funcDeclOrNil"

@gopherbot
Copy link

Change https://go.dev/cl/438540 mentions this issue: cmd/compile/internal/syntax: better error message for erroneous method declaration

@golang golang locked and limited conversation to collaborators Oct 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants