Compiler error for breaks inside non-loops scopes are confusing
| Originator: | DeFrenZ | ||
| Number: | rdar://23295682 | Date Originated: | 28-Oct-2015 04:00 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | swiftc 2.0 |
| Classification: | Enhancement | Reproducible: | Always |
Summary:
Doing a break inside a nested scope that's not a loop,
e.g.
do {
guard true else { break }
print("true")
}
gives this compiler error message:
error: 'break' is only allowed inside a loop, if, do, or switch
which makes you think that you can't do what you're doing at all, while you just have to annotate the scope with a label and break that instead,
e.g.
doLabel: do {
guard true else { break doLabel }
print("true")
}
Steps to Reproduce:
Just use unlabelled break inside a non-loop scope
Expected Results:
I expected it to compile, or tell me that for breaking there I needed to use a scope label in the compile error
Actual Results:
It doesn't compile and the error is confusing
Regression:
None I think
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!