Skip to content

Commit 95b6799

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 0419c38 commit 95b6799

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/Sema/TypeCheckMacros.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -971,11 +971,17 @@ static CharSourceRange getExpansionInsertionRange(MacroRole role,
971971
}
972972

973973
case MacroRole::Body: {
974-
if (target.is<Expr *>()) {
974+
if (auto *expr = target.dyn_cast<Expr *>()) {
975+
ASSERT(isa<ClosureExpr>(expr));
976+
977+
auto *closure = cast<ClosureExpr>(expr);
975978
// A closure body macro expansion replaces the full source
976-
// range of the closure.
979+
// range of the closure body starting from `in` and ending right
980+
// before the closing brace.
977981
return Lexer::getCharSourceRangeFromSourceRange(
978-
sourceMgr, target.getSourceRange());
982+
sourceMgr, SourceRange(Lexer::getLocForEndOfToken(
983+
sourceMgr, closure->getInLoc()),
984+
closure->getEndLoc()));
979985
}
980986

981987
SourceLoc afterDeclLoc =

0 commit comments

Comments
 (0)