Skip to content

Commit ca2013e

Browse files
committed
Macros: Escape init when printing names for attached macros.
Older compilers can't parse `name(init)`. Restore the call to `escapeKeywordInContext()` to ensure special names get escaped. Resolves rdar://108806697
1 parent e7a2408 commit ca2013e

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

lib/AST/Attr.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,9 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
13841384
if (macroIntroducedNameRequiresArgument(name.getKind())) {
13851385
SmallString<32> buffer;
13861386
StringRef nameText = name.getName().getString(buffer);
1387-
bool shouldEscape = nameText == "$";
1387+
bool shouldEscape =
1388+
escapeKeywordInContext(nameText, PrintNameContext::Normal) ||
1389+
nameText == "$";
13881390
Printer << "(";
13891391
if (shouldEscape)
13901392
Printer << "`";

test/ModuleInterface/macros.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
@attached(accessor) public macro myWrapper() = #externalMacro(module: "SomeModule", type: "Wrapper")
3939

4040
// CHECK: #if compiler(>=5.3) && $Macros && $AttachedMacros
41-
// CHECK: @attached(member, names: named(init), prefixed(`$`)) public macro MemberwiseInit() -> () = #externalMacro(module: "SomeModule", type: "MemberwiseInitMacro")
41+
// CHECK: @attached(member, names: named(`init`), prefixed(`$`)) public macro MemberwiseInit() -> () = #externalMacro(module: "SomeModule", type: "MemberwiseInitMacro")
4242
// CHECK-NEXT: #endif
4343
@attached(member, names: named(init), prefixed(`$`)) public macro MemberwiseInit() -> () = #externalMacro(module: "SomeModule", type: "MemberwiseInitMacro")
4444

0 commit comments

Comments
 (0)