Skip to content

Commit 07099a3

Browse files
committed
Effects: do not recurse into #selector effects because the code never runs
Fixes rdar://151968656
1 parent 5382e12 commit 07099a3

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/Sema/TypeCheckEffects.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,8 @@ class EffectsHandlingWalker : public ASTWalker {
713713
}
714714
} else if (auto TE = dyn_cast<MakeTemporarilyEscapableExpr>(E)) {
715715
recurse = asImpl().checkTemporarilyEscapable(TE);
716+
} else if (auto OSE = dyn_cast<ObjCSelectorExpr>(E)) {
717+
recurse = asImpl().checkObjCSelector(OSE);
716718
}
717719

718720
// Error handling validation (via checkTopLevelEffects) happens after
@@ -2269,6 +2271,10 @@ class ApplyClassifier {
22692271
return ShouldRecurse;
22702272
}
22712273

2274+
ShouldRecurse_t checkObjCSelector(ObjCSelectorExpr *E) {
2275+
return ShouldNotRecurse;
2276+
}
2277+
22722278
ConditionalEffectKind checkExhaustiveDoBody(DoCatchStmt *S) {
22732279
// All errors thrown by the do body are caught, but any errors thrown
22742280
// by the catch bodies are bounded by the throwing kind of the do body.
@@ -2418,6 +2424,10 @@ class ApplyClassifier {
24182424
return ShouldRecurse;
24192425
}
24202426

2427+
ShouldRecurse_t checkObjCSelector(ObjCSelectorExpr *E) {
2428+
return ShouldNotRecurse;
2429+
}
2430+
24212431
void visitExprPre(Expr *expr) { return; }
24222432
};
24232433

@@ -2535,6 +2545,10 @@ class ApplyClassifier {
25352545
return ShouldRecurse;
25362546
}
25372547

2548+
ShouldRecurse_t checkObjCSelector(ObjCSelectorExpr *E) {
2549+
return ShouldNotRecurse;
2550+
}
2551+
25382552
void visitExprPre(Expr *expr) { return; }
25392553
};
25402554

@@ -4026,6 +4040,10 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
40264040
return ShouldRecurse;
40274041
}
40284042

4043+
ShouldRecurse_t checkObjCSelector(ObjCSelectorExpr *E) {
4044+
return ShouldNotRecurse;
4045+
}
4046+
40294047
ConditionalEffectKind checkExhaustiveDoBody(DoCatchStmt *S) {
40304048
// This is a context where errors are handled.
40314049
ContextScope scope(*this, CurContext.withHandlesErrors());

test/expr/primary/selector/selector.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,11 @@ extension SomeProtocol {
172172
func test() -> Selector {
173173
#selector(OverloadedFuncAndProperty.f)
174174
}
175+
176+
@objc protocol HasThrows {
177+
@objc optional func doSomething(to object: AnyObject) throws -> Void
178+
}
179+
180+
func testWithThrowing(obj: AnyObject) {
181+
_ = #selector(HasThrows.doSomething(to:))
182+
}

0 commit comments

Comments
 (0)