-
Notifications
You must be signed in to change notification settings - Fork 10.5k
RangeInfo: disallow expressions with non-void type at the start or the end of multi-statement selections. #8092
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
Conversation
…e end of multi-statement selections.
@swift-ci please smoke test |
What happens when someone has a call to a @discardableResult func foo() -> Bool { return true }
func test() {
foo() // non-void type!
} |
oh, that's a good point. I think we should allow this as a special case. |
Please don't special-case it syntactically. I think you just need a better test for "top-level expression". Maybe it makes more sense to say "they must all be children of the same BraceStmt"? |
After all, selecting from outside an |
@jrose-apple I think "children of the same BraceStmt" is a better criterion here. I'll rework this patch. 👍 |
@jrose-apple hmm, actually this approach works well on other cases but not so much inside switch statements, for two reasons: (1) switch statement encloses directly case clauses, no brace stmt is involved; (2) case stmt can also enclose valid multi-statement selection without brace stmt in between. |
CaseStmts use BraceStmt too, it's just implicit: func test(x: Int) {
switch x {
case 1:
1
default:
0
}
}
I think we deliberately don't have any other grouping mechanism for statements. (Decls are another story. And top-level code makes this confusing.) |
No description provided.