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.
This commit is contained in:
Slava Pestov
2024-04-23 22:26:03 -04:00
parent 70c3e432f6
commit 83bb9d0fe2
2 changed files with 20 additions and 4 deletions

View File

@@ -627,16 +627,16 @@ public:
CaptureInfo CaptureInfoRequest::evaluate(Evaluator &evaluator,
AbstractFunctionDecl *AFD) const {
BraceStmt *body = AFD->getTypecheckedBody();
auto type = AFD->getInterfaceType();
if (type->is<ErrorType>() || body == nullptr)
if (type->is<ErrorType>())
return CaptureInfo::empty();
bool isNoEscape = type->castTo<AnyFunctionType>()->isNoEscape();
FindCapturedVars finder(AFD->getLoc(), AFD, isNoEscape,
AFD->isObjC(), AFD->isGeneric());
body->walk(finder);
if (auto *body = AFD->getTypecheckedBody())
body->walk(finder);
if (!AFD->isObjC()) {
finder.checkType(type, AFD->getLoc());

View File

@@ -0,0 +1,16 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -experimental-skip-non-inlinable-function-bodies-without-types %s -emit-module-path %t/skip_local_function_bodies.swiftmodule
public protocol P {
init()
}
extension P {
public func f() {
typealias T = Self
func g(_ x: T) {}
g(self)
}
}