Skip to content

Commit 83bb9d0

Browse files
committed
Sema: Fix regression with -experimental-skip-non-inlinable-function-bodies-without-types
My recent capture analysis refactoring broke a subtle corner case that wasn't exercised by the test suite. If a local inside g() was skipped, but the outer function was not skipped, we would return the empty list of captures for g(). But if the interface type of g() actually involves an outer generic parameter type, then the empty capture list did not record the fact that a generic signature was needed, so we attempted to form a call to the local function without a generic signature.
1 parent 70c3e43 commit 83bb9d0

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

lib/Sema/TypeCheckCaptures.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -627,16 +627,16 @@ class FindCapturedVars : public ASTWalker {
627627

628628
CaptureInfo CaptureInfoRequest::evaluate(Evaluator &evaluator,
629629
AbstractFunctionDecl *AFD) const {
630-
BraceStmt *body = AFD->getTypecheckedBody();
631-
632630
auto type = AFD->getInterfaceType();
633-
if (type->is<ErrorType>() || body == nullptr)
631+
if (type->is<ErrorType>())
634632
return CaptureInfo::empty();
635633

636634
bool isNoEscape = type->castTo<AnyFunctionType>()->isNoEscape();
637635
FindCapturedVars finder(AFD->getLoc(), AFD, isNoEscape,
638636
AFD->isObjC(), AFD->isGeneric());
639-
body->walk(finder);
637+
638+
if (auto *body = AFD->getTypecheckedBody())
639+
body->walk(finder);
640640

641641
if (!AFD->isObjC()) {
642642
finder.checkType(type, AFD->getLoc());
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -experimental-skip-non-inlinable-function-bodies-without-types %s -emit-module-path %t/skip_local_function_bodies.swiftmodule
3+
4+
public protocol P {
5+
init()
6+
}
7+
8+
extension P {
9+
public func f() {
10+
typealias T = Self
11+
12+
func g(_ x: T) {}
13+
g(self)
14+
}
15+
}
16+

0 commit comments

Comments
 (0)