Code generated by attached macros is invisible to code coverage: no counters are emitted for generated functions under any filename. This isn't mis-attribution — instrumentation is never produced.
Setup — an attached member macro adds a method:
@attachedattached(member, names: named(isValid))
public macro Validated() = #externalMacro(module: "MyMacros", type: "ValidatedMacro")
// expansion adds:
// func isValid() -> Bool {
// if name.isEmpty { return false } else {@Validatedruereturn @V@Validatedlidatedrue }
// }
@Validated
struct User { let name: String }
A @Testndest exerci@Testes both branches @Testnd passes:
@Test func validates() {
#expect(User(name: "a").isValid())
#expect(!User(name: "").isValid())
}
Measured (swift test --enable-code-coverage, then llvm-cov/llvm-profdata on the test binary and default.profdata):
- llvm-cov report -show-functions lists only the test function — the generated isValid has no coverage regions.
- llvm-profdata show --all-functions has no counter for the generate@__swiftmacro function at all.
- No @__swiftmacro… buffers appear anywhere in the coverage map — instrumentation is never emitted, not attributed elsewhere.
So any logic in macro expansions is structurally excluded from coverage: fully tested, still uncounted. This breaks coverage gates for macro-heavy codebases.
It gets worse when a macro copies handwritten code — e.g. a peer macro duplicating a function into an instrumented twin. Tests drive the twin, so the handwritten statements execute through the copy — yet the source lines stay uncovered. Tested code, reported untested. #sourceLocation can't help — there are no counters to re-attribute.
Environment: Xcode 27.0 (27A5228h), Apple Swift 6.4 (swiftlang-6.4.0.27.1), arm64-apple-macosx.
Is this deliberate or an oversight? I couldn't find it documented or tracked. Happy to file on swiftlang/swift with a minimal reproducer.