-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: bad error message when type switch assertion used outside of type switch #24470
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
go/types gives a better error message:
so it's conceivable that the compiler could do as well. Marking for 1.11 in case we get to it, but definitively not urgent. |
Sorry, I should have included that result too. Thanks for doing the legwork.
Agreed! |
This is a cmd/compile/internal/syntax error. There's also inconsistency. For the following if x, ok = i.(type); ok {
fmt.Println("Hello, playground", x)
} using a |
Furthermore, the code: switch x = i.(type) {
case T:
} reports (in a syntax parser test):
while switch x, ok := i.(type) {
case T:
} reports (test case of issue):
The problem is in the asymmetric handling of type switch guards in the syntax parser. |
Change https://golang.org/cl/103615 mentions this issue: |
Fantastic - thanks very much @griesemer! For anyone following this issue, the output from my playground example is now:
|
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, and tip
What operating system and processor architecture are you using (
go env
)?What did you do?
https://play.golang.org/p/5SSETQWcdrI
I typed something similar to this example by accident. I meant to assert a specific type, but instead used the special type-switch-form of a type assertion by accident.
What did you expect to see?
An error message that clearly identifies the problem on line 10. e.g.
What did you see instead?
A number of error messages, the first of which is, to my mind, a derived/less significant error message:
It's early-ish in the morning, but my eyes got fixed on the first error message... and it took longer than is perhaps sensible to get to the meat of the problem which is the second error message.
cc: @griesemer / @mdempsky
Thanks to @mvdan for helping to confirm the issue.
The text was updated successfully, but these errors were encountered: