Skip to content

Commit 4ee7b66

Browse files
committed
[Macros] Allow the back-ticked named(init) to be treated like named(init).
My recent change to parse initializer names in the macro role introduced names now correctly distinguishes between the two forms, but this breaks any existing macros written with the back-ticked form. Treat the former as the latter to provide a grace period for such macros. Fixes rdar://108571834.
1 parent 46b5df0 commit 4ee7b66

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/AST/Decl.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10299,6 +10299,15 @@ void MacroDecl::getIntroducedNames(MacroRole role, ValueDecl *attachedTo,
1029910299
switch (expandedName.getKind()) {
1030010300
case MacroIntroducedDeclNameKind::Named: {
1030110301
names.push_back(DeclName(expandedName.getName()));
10302+
10303+
// Temporary hack: we previously allowed named(`init`) to mean the same
10304+
// thing as named(init), before the latter was supported. Smooth over the
10305+
// difference by treating the former as the latter, for a short time.
10306+
if (expandedName.getName().isSimpleName() &&
10307+
!expandedName.getName().getBaseName().isSpecial() &&
10308+
expandedName.getName().getBaseIdentifier().is("init"))
10309+
names.push_back(DeclName(DeclBaseName::createConstructor()));
10310+
1030210311
break;
1030310312
}
1030410313

test/Macros/macro_expand_synthesized_members.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
)
1414
macro addMembers() = #externalMacro(module: "MacroDefinition", type: "AddMembers")
1515

16+
@attached(
17+
member,
18+
names: named(`init`), named(Storage), named(storage), named(getStorage()), named(method)
19+
)
20+
macro addMembersQuotedInit() = #externalMacro(module: "MacroDefinition", type: "AddMembers")
21+
1622
@addMembers
1723
struct S {
1824
func useSynthesized() {
@@ -89,3 +95,11 @@ enum ElementType {
8995
}
9096

9197
print(ElementType.paper.unknown())
98+
99+
@addMembersQuotedInit
100+
struct S2 {
101+
func useSynthesized() {
102+
S.method()
103+
print(type(of: getStorage()))
104+
}
105+
}

0 commit comments

Comments
 (0)