assertMacro only applies fix-its when all emitted diagnostics have one or more fix-its, so fix-it coverage is lost when macros include diagnostics with and without fix-its. Instead, fixes should be included if any diagnostic has fix-its, even though it’s probable that the fixed source won’t resolve all the diagnostics. (I say “probable” because it is possible, yet unusual, for one fix-it to resolve multiple diagnostics.)
Currently, the following test:
func testInvalidLabelAndDefaultOnMultipleBindings() {
assertMacro {
"""
@MemberwiseInit
struct S {
@Init(default: 0, label: "$foo") let x, y: T
}
"""
}
}
records with just diagnostics:
func testInvalidLabelAndDefaultOnMultipleBindings() {
assertMacro {
"""
@MemberwiseInit
struct S {
@Init(default: 0, label: "$foo") let x, y: T
}
"""
} diagnostics: {
"""
@MemberwiseInit
struct S {
@Init(default: 0, label: "$foo") let x, y: T
┬────────────
│ ╰─ 🛑 Custom 'label' can't be applied to multiple bindings
┬──────────
╰─ 🛑 Custom 'default' can't be applied to multiple bindings
✏️ Remove 'default: 0'
}
"""
}
}
I'd expect that the following fixes closure would be included after diagnostics:
[…]
} fixes: {
"""
@MemberwiseInit
struct S {
@Init(label: "$foo") let x, y: T
}
"""
}
Checklist
[X] If possible, I've reproduced the issue using the main branch of this package.
Description
assertMacro
only applies fix-its when all emitted diagnostics have one or more fix-its, so fix-it coverage is lost when macros include diagnostics with and without fix-its. Instead, fixes should be included if any diagnostic has fix-its, even though it’s probable that the fixed source won’t resolve all the diagnostics. (I say “probable” because it is possible, yet unusual, for one fix-it to resolve multiple diagnostics.)Currently, the following test:
records with just
diagnostics
:I'd expect that the following
fixes
closure would be included afterdiagnostics
:Checklist
main
branch of this package.Expected behavior
No response
Actual behavior
No response
Steps to reproduce
No response
swift-macro-testing version information
0.2.0, main (15916c0)
Destination operating system
macOS 14.2
Xcode version information
Xcode Version 15.1 (15C65)
Swift Compiler version information