Skip to content

Commit 6ae727a

Browse files
authored
Merge pull request #65443 from DougGregor/macro-name-back-ticked-init-as-init-5.9
2 parents db30ee5 + 4ee7b66 commit 6ae727a

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)