Skip to content

Commit 8469abb

Browse files
author
David Ungar
committed
Fix expansion of lazily-parsed function bodies
1 parent 4ab5c6b commit 8469abb

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

lib/AST/ASTScopeCreation.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,8 +1360,8 @@ void AbstractFunctionDeclScope::expandAScopeThatDoesNotCreateANewInsertionPoint(
13601360
}
13611361
// Create scope for the body.
13621362
// We create body scopes when there is no body for source kit to complete
1363-
// erroneous code in bodies. But don't let compiler synthesize one.
1364-
if (decl->getBodySourceRange().isValid() && decl->getBody(false)) {
1363+
// erroneous code in bodies.
1364+
if (decl->getBodySourceRange().isValid()) {
13651365
if (AbstractFunctionBodyScope::isAMethod(decl))
13661366
scopeCreator.constructExpandAndInsertUncheckable<MethodBodyScope>(leaf,
13671367
decl);
@@ -1902,6 +1902,7 @@ void AbstractFunctionBodyScope::beCurrent() {
19021902
bodyWhenLastExpanded = decl->getBody(false);
19031903
}
19041904
bool AbstractFunctionBodyScope::isCurrentIfWasExpanded() const {
1905+
// Pass in false to keep the compiler from synthesizing one.
19051906
return bodyWhenLastExpanded == decl->getBody(false);
19061907
}
19071908

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Body of closure in parameter to call of closureTaker is created lazily
2+
// and this test ensures that that body scope does get expanded
3+
var v = closureTaker {
4+
func amIFound() {}
5+
}
6+
7+
func closureTaker(_: () -> Void )
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Ensure that a lazily-parsed function body gets expanded
2+
3+
// RUN: %target-swift-frontend -typecheck -primary-file %s %S/Inputs/lazy_function_body_expansion_helper.swift
4+
5+
let a = v

0 commit comments

Comments
 (0)