Skip to content

Commit 020987a

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 8f1b5c7 commit 020987a

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
@@ -1376,7 +1376,9 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
13761376
if (macroIntroducedNameRequiresArgument(name.getKind())) {
13771377
SmallString<32> buffer;
13781378
StringRef nameText = name.getName().getString(buffer);
1379-
bool shouldEscape = nameText == "$";
1379+
bool shouldEscape =
1380+
escapeKeywordInContext(nameText, PrintNameContext::Normal) ||
1381+
nameText == "$";
13801382
Printer << "(";
13811383
if (shouldEscape)
13821384
Printer << "`";

test/ModuleInterface/macros.swift

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

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

0 commit comments

Comments
 (0)