Skip to content

Commit 2b70025

Browse files
committed
[Builder transform] Give generated pattern bindings proper source locations.
ASTScopes completely skip implicit pattern bindings, so don't mark generated ones as implicit. Instead, give them suitable source location information. Fixes rdar://problem/58710568.
1 parent 8283a67 commit 2b70025

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

lib/Sema/BuilderTransform.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,8 @@ class BuilderClosureRewriter
730730
/// Declare the given temporary variable, adding the appropriate
731731
/// entries to the elements of a brace stmt.
732732
void declareTemporaryVariable(VarDecl *temporaryVar,
733-
std::vector<ASTNode> &elements) {
733+
std::vector<ASTNode> &elements,
734+
Expr *initExpr = nullptr) {
734735
if (!temporaryVar)
735736
return;
736737

@@ -739,7 +740,9 @@ class BuilderClosureRewriter
739740
auto pattern = new (ctx) NamedPattern(temporaryVar,/*implicit=*/true);
740741
pattern->setType(temporaryVar->getType());
741742

742-
auto pbd = PatternBindingDecl::createImplicit(ctx, StaticSpellingKind::None, pattern, nullptr, dc);
743+
auto pbd = PatternBindingDecl::create(
744+
ctx, SourceLoc(), StaticSpellingKind::None, temporaryVar->getLoc(),
745+
pattern, SourceLoc(), initExpr, dc);
743746
elements.push_back(temporaryVar);
744747
elements.push_back(pbd);
745748
}
@@ -789,13 +792,7 @@ class BuilderClosureRewriter
789792

790793
// Form a new pattern binding to bind the temporary variable to the
791794
// transformed expression.
792-
auto pattern = new (ctx) NamedPattern(
793-
recorded.temporaryVar, /*implicit=*/true);
794-
pattern->setType(recorded.temporaryVar->getType());
795-
newElements.push_back(recorded.temporaryVar);
796-
797-
auto pbd = PatternBindingDecl::createImplicit(ctx, StaticSpellingKind::None, pattern, finalExpr, dc);
798-
newElements.push_back(pbd);
795+
declareTemporaryVariable(recorded.temporaryVar, newElements, finalExpr);
799796
continue;
800797
}
801798

0 commit comments

Comments
 (0)