Skip to content

Commit 0b328f7

Browse files
authored
Merge pull request #69446 from DougGregor/member-conformance-list-for-real
2 parents 5bc78e1 + 86863f4 commit 0b328f7

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

lib/Sema/TypeCheckMacros.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,7 @@ static SourceFile *evaluateAttachedMacro(MacroDecl *macro, Decl *attachedTo,
13191319
std::string conformanceList;
13201320
{
13211321
llvm::raw_string_ostream OS(conformanceList);
1322-
if (role == MacroRole::Extension) {
1322+
if (role == MacroRole::Extension || role == MacroRole::Member) {
13231323
llvm::interleave(
13241324
conformances,
13251325
[&](const ProtocolDecl *protocol) {

test/Macros/Inputs/syntax_macro_definitions.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,13 +2041,19 @@ extension RequiredDefaultInitMacro: MemberMacro {
20412041
conformingTo protocols: [TypeSyntax],
20422042
in context: some MacroExpansionContext
20432043
) throws -> [DeclSyntax] {
2044-
let decl: DeclSyntax
2045-
if declaration.is(ClassDeclSyntax.self) && protocols.isEmpty {
2046-
decl = "required init() { }"
2044+
let initDecl: DeclSyntax
2045+
let funcDecl: DeclSyntax
2046+
if !declaration.is(ClassDeclSyntax.self) {
2047+
initDecl = "init() { }"
2048+
funcDecl = "func f() { }"
2049+
} else if !protocols.isEmpty {
2050+
initDecl = "required init() { }"
2051+
funcDecl = "func f() { }"
20472052
} else {
2048-
decl = "init() { }"
2053+
initDecl = "required init() { }"
2054+
funcDecl = "override func f() { }"
20492055
}
2050-
return [ decl ]
2056+
return [ initDecl, funcDecl ]
20512057
}
20522058
}
20532059

test/Macros/macro_expand_member_with_conformances.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ protocol DefaultInit {
99
}
1010

1111
@attached(extension, conformances: DefaultInit)
12-
@attached(member, conformances: DefaultInit, names: named(init()))
12+
@attached(member, conformances: DefaultInit, names: named(init()), named(f()))
1313
macro DefaultInit() = #externalMacro(module: "MacroDefinition", type: "RequiredDefaultInitMacro")
1414

1515
@DefaultInit

0 commit comments

Comments
 (0)