File tree Expand file tree Collapse file tree 4 files changed +59
-0
lines changed Expand file tree Collapse file tree 4 files changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -393,6 +393,10 @@ static bool hasUnhandledError(ArrayRef<ASTNode> Nodes) {
393
393
return !Throwing;
394
394
}
395
395
bool walkToExprPre (Expr *E) override {
396
+ // Don't walk into closures, they only produce effects when called.
397
+ if (isa<ClosureExpr>(E))
398
+ return false ;
399
+
396
400
if (isa<TryExpr>(E)) {
397
401
Throwing = true ;
398
402
}
Original file line number Diff line number Diff line change
1
+ enum Err : Error {
2
+ case wat
3
+ }
4
+
5
+ func throwsSomething() throws { throw Err.wat }
6
+ func consumesErrClosure(_ fn: () throws -> Void) {}
7
+ func rethrowsErrClosure(_ fn: () throws -> Void) rethrows {}
8
+
9
+ fileprivate func new_name() {
10
+ consumesErrClosure { throw Err.wat }
11
+ consumesErrClosure { try throwsSomething() }
12
+ }
13
+
14
+ func testThrowingClosure() throws {
15
+ new_name()
16
+ try rethrowsErrClosure { try throwsSomething() }
17
+ }
18
+
Original file line number Diff line number Diff line change
1
+ enum Err : Error {
2
+ case wat
3
+ }
4
+
5
+ func throwsSomething() throws { throw Err.wat }
6
+ func consumesErrClosure(_ fn: () throws -> Void) {}
7
+ func rethrowsErrClosure(_ fn: () throws -> Void) rethrows {}
8
+
9
+ fileprivate func new_name() throws {
10
+ consumesErrClosure { throw Err.wat }
11
+ consumesErrClosure { try throwsSomething() }
12
+ try rethrowsErrClosure { try throwsSomething() }
13
+ }
14
+
15
+ func testThrowingClosure() throws {
16
+ try new_name()
17
+ }
18
+
Original file line number Diff line number Diff line change
1
+ enum Err : Error {
2
+ case wat
3
+ }
4
+
5
+ func throwsSomething( ) throws { throw Err . wat }
6
+ func consumesErrClosure( _ fn: ( ) throws -> Void ) { }
7
+ func rethrowsErrClosure( _ fn: ( ) throws -> Void ) rethrows { }
8
+
9
+ func testThrowingClosure( ) throws {
10
+ consumesErrClosure { throw Err . wat }
11
+ consumesErrClosure { try throwsSomething ( ) }
12
+ try rethrowsErrClosure { try throwsSomething ( ) }
13
+ }
14
+
15
+ // RUN: %empty-directory(%t.result)
16
+ // RUN: %refactor -extract-function -source-filename %s -pos=10:1 -end-pos=11:47 >> %t.result/consumes_err.swift
17
+ // RUN: diff -u %S/Outputs/throw_errors3/consumes_err.swift.expected %t.result/consumes_err.swift
18
+ // RUN: %refactor -extract-function -source-filename %s -pos=10:1 -end-pos=12:51 >> %t.result/rethrows_err.swift
19
+ // RUN: diff -u %S/Outputs/throw_errors3/rethrows_err.swift.expected %t.result/rethrows_err.swift
You can’t perform that action at this time.
0 commit comments