I'm using the latest Xcode 15 beta 3 (15A5195k) with CLTs (15A5195k). For the purpose of showcasing the behaviour I created a fresh macro Package. I added an attached(conformance)
macro and implemented it. When using the macro, the compiler throws an error Macro implementation type 'xxx' doesn't conform to required protocol 'ConformanceMacro'
even though conformance to ConformanceMacro
should be done correctly.
My setup is the following:
Package.swift
let package = Package(
name: "SampleMacro",
platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6), .macCatalyst(.v13)],
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "SampleMacro",
targets: ["SampleMacro"]
),
.executable(
name: "SampleMacroClient",
targets: ["SampleMacroClient"]
),
],
dependencies: [
// Depend on the latest Swift 5.9 prerelease of SwiftSyntax
.package(url: "https://github.com/apple/swift-syntax.git", from: "509.0.0-swift-5.9-DEVELOPMENT-SNAPSHOT-2023-04-25-b"),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
// Macro implementation that performs the source transformation of a macro.
.macro(
name: "SampleMacroMacros",
dependencies: [
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftCompilerPlugin", package: "swift-syntax")
]
),
// Library that exposes a macro as part of its API, which is used in client programs.
.target(name: "SampleMacro", dependencies: ["SampleMacroMacros"]),
// A client of the library, which is able to use the macro in its own code.
.executableTarget(name: "SampleMacroClient", dependencies: ["SampleMacro"]),
// A test target used to develop the macro implementation.
.testTarget(
name: "SampleMacroTests",
dependencies: [
"SampleMacroMacros",
.product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
]
),
]
)
SampleMacroMacro.swift
@main
struct SampleMacroPlugin: CompilerPlugin {
let providingMacros: [Macro.Type] = [
ProtocolConformanceMacro.self,
]
}
ProtocolConformanceMacro.swift
public enum ProtocolConformanceMacro {
}
extension ProtocolConformanceMacro: ConformanceMacro {
public static func expansion(
of node: AttributeSyntax,
providingConformancesOf declaration: some DeclGroupSyntax,
in context: some MacroExpansionContext
) throws -> [(TypeSyntax, GenericWhereClauseSyntax?)] {
[("IamNothing", nil)]
}
}
The implementation is simply:
@ProtocolConformanceMacro
struct SampleStruct {
}
Not sure if this is a bug or I just did something incorrectly.