Skip to content

Commit 006537e

Browse files
authored
Merge pull request #65442 from DougGregor/macro-name-back-ticked-init-as-init
2 parents 1808850 + 0725367 commit 006537e

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
@@ -10307,6 +10307,15 @@ void MacroDecl::getIntroducedNames(MacroRole role, ValueDecl *attachedTo,
1030710307
switch (expandedName.getKind()) {
1030810308
case MacroIntroducedDeclNameKind::Named: {
1030910309
names.push_back(DeclName(expandedName.getName()));
10310+
10311+
// Temporary hack: we previously allowed named(`init`) to mean the same
10312+
// thing as named(init), before the latter was supported. Smooth over the
10313+
// difference by treating the former as the latter, for a short time.
10314+
if (expandedName.getName().isSimpleName() &&
10315+
!expandedName.getName().getBaseName().isSpecial() &&
10316+
expandedName.getName().getBaseIdentifier().is("init"))
10317+
names.push_back(DeclName(DeclBaseName::createConstructor()));
10318+
1031010319
break;
1031110320
}
1031210321

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)