8000 The conformance role does not expand in the test case. · Issue #1801 · swiftlang/swift-syntax · GitHub
[go: up one dir, main page]

Skip to content

The conformance role does not expand in the test case. #1801

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

Closed
liaoyuanng opened this issue Jun 16, 2023 · 1 comment
Closed

The conformance role does not expand in the test case. #1801

liaoyuanng opened this issue Jun 16, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@liaoyuanng
Copy link

Description

@attached(conformance)
public macro demonstration() = #externalMacro(module: "WWDC23Macros", type: "DemostrationMacro")

extension DemostrationMacro: ConformanceMacro {
    public static func expansion<Declaration, Context>(
        of node: AttributeSyntax,
        providingConformancesOf declaration: Declaration,
        in context: Context
    ) throws -> [(TypeSyntax, GenericWhereClauseSyntax?)] where Declaration : DeclGroupSyntax, Context : MacroExpansionContext {
                
        return [("DemonstrationProtocol", nil)]
}


@main
struct WWDCHelperPlugin: CompilerPlugin {
    let providingMacros: [Macro.Type] = [
        DemostrationMacro.self
    ]
}

// in Test file
let testMacros: [String: Macro.Type] = [
    "demonstration": DemostrationMacro.self,
]

func testMacro() {
        assertMacroExpansion(
            """
            @demonstration()
            class TestClass {
            }
            """,
            expandedSource: """
            
            class TestClass {
            }
            extension TestClass : DemonstrationProtocol  {}
            """,
            macros: testMacros
        )
 }

There is an error when I run the test case:

error: -[WWDC23Tests.WWDC23Tests testMacro] : failed - Actual output (+) differed from expected output (-):
 
class TestClass {
 }extension TestClass : DemonstrationProtocol  {}

But it runs fine when I execute it in the code.
image

It seems that the macro is missing the last line when it expands in the test.

Steps to Reproduce

No response

@liaoyuanng liaoyuanng added the bug Something isn't working label Jun 16, 2023
@liaoyuanng liaoyuanng changed the title The Role of conformance does not expand in test case The conformance role does not expand in the test case. Jun 16, 2023
@ahoppen
Copy link
Member
ahoppen commented Jun 16, 2023

Thanks for reporting. This is a duplicate of #1742 and has been fixed by #1742

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants
0