-
Notifications
You must be signed in to change notification settings - Fork 17.5k
-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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 (but accurate) error message for function with variadic arguments if argument is not the last #28450
Comments
Thank you for filing this issue @loren-osborn and welcome to the Go project! @griesemer @mdempsky, what do y'all think of these suggestions? missing type for argument bar (can only use ... with final parameter in list) b) missing type for argument bar b) is succinct but will likely generate more confusion say if the function signature contains more than one such repeated field e.g. func Foo(bar, foo, fizz, args ...interface{}) {
} Hence I am leaning towards suggestion a) which will print out missing type for argument bar (can only use ... with final parameter in list)
missing type for argument foo (can only use ... with final parameter in list)
missing type for argument fizz (can only use ... with final parameter in list) or later on, perhaps after the frontend overhaul we can provide a more concise message missing type for arguments bar, foo, fizz: ... can only be used for the final parameter |
Thank you for the report. I agree that the error message can be improved. Certainly, the error's column number information should at least point at the non-final parameter in question, and probably the parameter's name can be incorporated into the error message. I think these would address the raised issue about users misfocusing on However, I disagree with the proposed "missing type" wording. In the linked example (https://play.golang.org/p/2EFkTjC3KhA), I'd probably lean towards changing the error message to:
|
Not urgent. Good starter project. |
@mdempsky, I almost agree. The problem is that |
Change https://golang.org/cl/152417 mentions this issue: |
Change https://golang.org/cl/152758 mentions this issue: |
Follow-up on #28450 (golang.org/cl/152417). Updates #28450. Fixes #29107. Change-Id: Ib4b4fe582c35315a4f71cf6dbc7f7f2f24b37ec1 Reviewed-on: https://go-review.googlesource.com/c/152758 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go1.10 and playground (1.11)
Does this issue reproduce with the latest release?
Yes. Example: https://play.golang.org/p/kE_ICtDSVzU
What operating system and processor architecture are you using (
go env
)?darwin/amd64
What did you do?
I forgot to include an argument type prior to a final variadic function argument.
Here is an example: https://play.golang.org/p/kE_ICtDSVzU
In this example,
bar
was intended to be a string, but the compiler had no way of knowing this.What did you expect to see?
Given the code I was attempting to compile, I would expect an error message to identify a
since, (as the actual error message indicated,
only use ... with final parameter in list
) a variadic type ofargs
should not be applied to a list of arguments.What did you see instead?
Error message
Removing developer attention from
bar
and directed it towardargs ...interface{}
The text was updated successfully, but these errors were encountered: