Skip to content

Commit e5bd6c8

Browse files
committed
Macros: Escape init and subscript when printing names for attached macros.
Older compilers can't parse `name(init)` and `name(subscript)`. Resolves rdar://108806697
1 parent e7a2408 commit e5bd6c8

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

lib/AST/Attr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,8 @@ 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 = nameText == "$" || nameText == "init" ||
1388+
nameText == "subscript";
13881389
Printer << "(";
13891390
if (shouldEscape)
13901391
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)