Skip to content

Commit 42b89f1

Browse files
authored
Merge pull request #69447 from DougGregor/member-conformance-list-for-real-5.10
2 parents 8a1590d + 57f1fc6 commit 42b89f1

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
@@ -1270,7 +1270,7 @@ static SourceFile *evaluateAttachedMacro(MacroDecl *macro, Decl *attachedTo,
12701270
std::string conformanceList;
12711271
{
12721272
llvm::raw_string_ostream OS(conformanceList);
1273-
if (role == MacroRole::Extension) {
1273+
if (role == MacroRole::Extension || role == MacroRole::Member) {
12741274
llvm::interleave(
12751275
conformances,
12761276
[&](const ProtocolDecl *protocol) {

test/Macros/Inputs/syntax_macro_definitions.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,13 +2045,19 @@ extension RequiredDefaultInitMacro: MemberMacro {
20452045
conformingTo protocols: [TypeSyntax],
20462046
in context: some MacroExpansionContext
20472047
) throws -> [DeclSyntax] {
2048-
let decl: DeclSyntax
2049-
if declaration.is(ClassDeclSyntax.self) && protocols.isEmpty {
2050-
decl = "required init() { }"
2048+
let initDecl: DeclSyntax
2049+
let funcDecl: DeclSyntax
2050+
if !declaration.is(ClassDeclSyntax.self) {
2051+
initDecl = "init() { }"
2052+
funcDecl = "func f() { }"
2053+
} else if !protocols.isEmpty {
2054+
initDecl = "required init() { }"
2055+
funcDecl = "func f() { }"
20512056
} else {
2052-
decl = "init() { }"
2057+
initDecl = "required init() { }"
2058+
funcDecl = "override func f() { }"
20532059
}
2054-
return [ decl ]
2060+
return [ initDecl, funcDecl ]
20552061
}
20562062
}
20572063

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)