Skip to content

Commit 0c1033a

Browse files
committed
Fix AST scoping
1 parent f003c49 commit 0c1033a

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

lib/AST/ASTScopeCreation.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,14 @@ ASTSourceFileScope::ASTSourceFileScope(SourceFile *SF,
272272

273273
// Determine the parent source location based on the macro role.
274274
AbstractFunctionDecl *bodyForDecl = nullptr;
275+
276+
if (SF->Kind == SourceFileKind::DefaultArgument) {
277+
auto genInfo = *SF->getASTContext().SourceMgr.getGeneratedSourceInfo(
278+
*SF->getBufferID());
279+
parentLoc = ASTNode::getFromOpaqueValue(genInfo.astNode).getStartLoc();
280+
goto setParent;
281+
}
282+
275283
switch (*macroRole) {
276284
case MacroRole::Expression:
277285
case MacroRole::Declaration:
@@ -301,6 +309,7 @@ ASTSourceFileScope::ASTSourceFileScope(SourceFile *SF,
301309
}
302310
}
303311

312+
setParent:
304313
if (auto parentScope = findStartingScopeForLookup(enclosingSF, parentLoc)) {
305314
if (bodyForDecl) {
306315
auto bodyScope = new (bodyForDecl->getASTContext()) FunctionBodyScope(bodyForDecl);

lib/AST/Module.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,8 @@ llvm::Optional<MacroRole> SourceFile::getFulfilledMacroRole() const {
12221222
}
12231223

12241224
SourceFile *SourceFile::getEnclosingSourceFile() const {
1225-
if (Kind != SourceFileKind::MacroExpansion)
1225+
if (Kind != SourceFileKind::MacroExpansion &&
1226+
Kind != SourceFileKind::DefaultArgument)
12261227
return nullptr;
12271228

12281229
auto genInfo =

lib/Sema/TypeCheckExpr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,7 @@ static Expr *synthesizeCallerSideDefault(const ParamDecl *param,
774774
#include "swift/AST/MagicIdentifierKinds.def"
775775

776776
case DefaultArgumentKind::ExpressionMacro: {
777+
// FIXME: ApolloZhu serialize and deserialize expressions instead
777778
SmallString<128> scratch;
778779
const StringRef text = param->getDefaultValueStringRepresentation(scratch);
779780
SourceFile *defaultArgSourceFile =

0 commit comments

Comments
 (0)