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: bad error message for argument missing type #69506

Open
prattmic opened this issue Sep 17, 2024 · 4 comments
Open

cmd/compile: bad error message for argument missing type #69506

prattmic opened this issue Sep 17, 2024 · 4 comments
Assignees
Labels
BadErrorMessage Issues related compiler error messages that should be better. compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@prattmic
Copy link
Member

Go version

1.23

Output of go env in your module/workspace:

N/A

What did you do?

https://go.dev/play/p/hgKdYn08tsY

I forgot to add the type to the last argument of a function definition:

func f(a int, b) {
}

This should have some type name after b.

What did you see happen?

./prog.go:7:15: syntax error: mixed named and unnamed parameters

What did you expect to see?

All parameters are named here, the actual problem is the missing type, so I expected something like: "syntax error: parameter 'b' missing type"

@prattmic prattmic added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 17, 2024
@prattmic
Copy link
Member Author

cc @golang/compiler

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Sep 17, 2024
@prattmic
Copy link
Member Author

Thanks @gabyhelp. #10762 points out that this could be ambiguous. If b is a type, then the error message would be accurate.

Still, as a user I know b is not a type, so the error message is not very helpful.

@griesemer griesemer self-assigned this Sep 17, 2024
@griesemer griesemer added this to the Go1.24 milestone Sep 17, 2024
@adonovan
Copy link
Member

This error comes from the parser, so it can't use knowledge of what kind of symbol b is. I suppose the type checker could emit a second error:

./prog.go:7:15: syntax error: mixed named and unnamed parameters
./prog.go:7:15: type error: parameter b has no type

@cherrymui cherrymui added the BadErrorMessage Issues related compiler error messages that should be better. label Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BadErrorMessage Issues related compiler error messages that should be better. compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Status: No status
Development

No branches or pull requests

6 participants