diff --git a/lib/Sema/TypeCheckMacros.cpp b/lib/Sema/TypeCheckMacros.cpp index 9d599b54c4b95..ddaf3e02efa05 100644 --- a/lib/Sema/TypeCheckMacros.cpp +++ b/lib/Sema/TypeCheckMacros.cpp @@ -1239,7 +1239,7 @@ static SourceFile *evaluateAttachedMacro(MacroDecl *macro, Decl *attachedTo, std::string conformanceList; { llvm::raw_string_ostream OS(conformanceList); - if (role == MacroRole::Extension) { + if (role == MacroRole::Extension || role == MacroRole::Member) { llvm::interleave( conformances, [&](const ProtocolDecl *protocol) { diff --git a/test/Macros/Inputs/syntax_macro_definitions.swift b/test/Macros/Inputs/syntax_macro_definitions.swift index 07902bbb9c84a..a01a58146ad4e 100644 --- a/test/Macros/Inputs/syntax_macro_definitions.swift +++ b/test/Macros/Inputs/syntax_macro_definitions.swift @@ -2073,12 +2073,18 @@ extension RequiredDefaultInitMacro: MemberMacro { conformingTo protocols: [TypeSyntax], in context: some MacroExpansionContext ) throws -> [DeclSyntax] { - let decl: DeclSyntax - if declaration.is(ClassDeclSyntax.self) && protocols.isEmpty { - decl = "required init() { }" + let initDecl: DeclSyntax + let funcDecl: DeclSyntax + if !declaration.is(ClassDeclSyntax.self) { + initDecl = "init() { }" + funcDecl = "func f() { }" + } else if !protocols.isEmpty { + initDecl = "required init() { }" + funcDecl = "func f() { }" } else { - decl = "init() { }" + initDecl = "required init() { }" + funcDecl = "override func f() { }" } - return [ decl ] + return [ initDecl, funcDecl ] } } diff --git a/test/Macros/macro_expand_member_with_conformances.swift b/test/Macros/macro_expand_member_with_conformances.swift index a02e834464e79..ff37121069d2d 100644 --- a/test/Macros/macro_expand_member_with_conformances.swift +++ b/test/Macros/macro_expand_member_with_conformances.swift @@ -9,7 +9,7 @@ protocol DefaultInit { } @attached(extension, conformances: DefaultInit) -@attached(member, conformances: DefaultInit, names: named(init())) +@attached(member, conformances: DefaultInit, names: named(init()), named(f())) macro DefaultInit() = #externalMacro(module: "MacroDefinition", type: "RequiredDefaultInitMacro") @DefaultInit