-
Notifications
You must be signed in to change notification settings - Fork 18k
go/types: "const _ string = 1" error message says integers can't be converted to strings #22070
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
Comments
The accurate message should be There are many error messages are not very accurate. Another example: type T *int
type S struct {
T // error: embedded type cannot be a pointer
} The accurate message should be |
I think the correct wording is The embedded type error message reads fine to me as is. |
Yes, type T *int
type S struct {
T // error: embedded type cannot be a pointer
}
type S struct {
*int // ok.
} |
The error message is inaccurate, but we do get an error message. Not urgent. |
With current tip, the error message:
Should we close this @griesemer @mdempsky ? |
@cuonglm Thanks for noticing this. The compiler does the right think now. Still not urgent. |
Change https://golang.org/cl/242083 mentions this issue: |
The error returned by convertUntyped is 'cannot convert _ to _', which can be misleading in contexts where an explicit conversion would be allowed. Arguably the error message from convertUntyped should just be 'cannot use _ as _', as 'convert' has an explicit meaning within the spec. Making that change caused a large number of test failures, so for now we just fix this for assignments by interpreting the error. For #22070 Change-Id: I4eed6f39d1a991e8df7e035ec301d28a05150eb5 Reviewed-on: https://go-review.googlesource.com/c/go/+/242083 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Change https://golang.org/cl/267717 mentions this issue: |
CL 242083 corrected an inaccurate error message related to the assignability of untyped constant values. Previously the error message was of the form "cannot convert ... to ...", which is misleading when there is no explicit conversion in the syntax. The new error message corrected this to "cannot use ... as ... in ...", but also appended an inner error message that can be quite verbose. For example: cannot use "123" (untyped string constant) as int value in assignment: cannot convert "123" (untyped string constant) to int" This might be more accurate, but is a regression in readability. Correct this by only including the inner error message in the rare cases where it is helpful: if the constant value overflows or is truncated. For #22070 Change-Id: I8b8ee6ef713f64facc319894be09398b0b5ea500 Reviewed-on: https://go-review.googlesource.com/c/go/+/267717 Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Robert Griesemer <gri@golang.org> Trust: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org>
The error message is now "cannot use 1 (untyped int constant) as string value in constant declaration", so I think this can be closed. |
Compiling this package with cmd/compile (or go/types) produces an error message that 1 cannot be "converted" to type string. In fact it can be converted, it just can't be assigned, which is the criteria required here by the language spec.
/cc @griesemer
The text was updated successfully, but these errors were encountered: