Skip to content

Commit 68ce663

Browse files
xedinhborla
authored andcommitted
[Macros] A macro attached to a closure body covers a range after in and up to }
The macro is not allowed to write explicit type or `in` keyword.
1 parent e959f84 commit 68ce663

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/Sema/TypeCheckMacros.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -968,11 +968,17 @@ static CharSourceRange getExpansionInsertionRange(MacroRole role,
968968
}
969969

970970
case MacroRole::Body: {
971-
if (target.is<Expr *>()) {
971+
if (auto *expr = target.dyn_cast<Expr *>()) {
972+
ASSERT(isa<ClosureExpr>(expr));
973+
974+
auto *closure = cast<ClosureExpr>(expr);
972975
// A closure body macro expansion replaces the full source
973-
// range of the closure.
976+
// range of the closure body starting from `in` and ending right
977+
// before the closing brace.
974978
return Lexer::getCharSourceRangeFromSourceRange(
975-
sourceMgr, target.getSourceRange());
979+
sourceMgr, SourceRange(Lexer::getLocForEndOfToken(
980+
sourceMgr, closure->getInLoc()),
981+
closure->getEndLoc()));
976982
}
977983

978984
SourceLoc afterDeclLoc =

0 commit comments

Comments
 (0)