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
Build errors while placing an indentifier in a switch statement. #40603
Comments
Well, that is how the language works. Permitting a label on a switch x := v.(type) {
case int:
goto label
case float32:
break
label:
case int32:
// what is the type of x here?
} In other words, the same reasons that prevent you from jumping into a block also prevent you from jumping to a |
Since this is the way that the language is designed and intended, I'm going to close this issue. |
This is only a problem in a type switch. I don't see why the same thing can't be done for goto. |
True, it probably could be made to work, but the cost would be another exception to the language. If you want to propose a change to the language, see https://golang.org/s/proposal. But I would not accept this proposal to be accepted. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I have switch where there is a case A, case B and a default. The 2 cases must fallthough to the default (due to obvious geometrical reasons this can't fit), so one case get a fallthrough while the other goto a label placed before the default.
https://play.golang.org/p/Xh4eFsskySm
What did you expect to see?
I expect the first case to catch 1 and then jump over the case 2 and execute the default.
What did you see instead?
Build errors with :
./prog.go:12:11: syntax error: missing statement after label
.I also tried switching the place of the default and the label but this doesn't build (that expected since this would be jumping in a block).
The other case can also be completely removed and this still doesn't work (but yes with this a fallthrough could do it but that not what I need).
The text was updated successfully, but these errors were encountered: