Skip to content

[5.9] [Macros] Make sure we actually pass the conformance list to member macros #69448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckMacros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 11 additions & 5 deletions test/Macros/Inputs/syntax_macro_definitions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
}
}
2 changes: 1 addition & 1 deletion test/Macros/macro_expand_member_with_conformances.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down