Regression in Xcode 26.4: @Test expansion generates invalid code for @SnapshotSuite inside an extension-scoped @Suite
bugmacros
### Description
I’m seeing what looks like invalid Swift Testing macro expansion in Xcode 26.4 when @Test is generated inside an extension-scoped @Suite.
This comes from my macros package, swift-snapshot-testing-macros:
https://github.com/adammcarter/swift-snapshot-testing-macros
This appears to be a regression: the same package and test target worked under Xcode 26.3, but fail under Xcode 26.4.
The authored source is valid, but compilation fails in generated @__swiftmacro_*.swift files with diagnostics like:
- Properties with attribute @used must be static
- Properties with attribute @section must be static
- Cannot use instance member '...' within property initializer; property initializers run before 'self' is available
- Static member '...' cannot be used on instance of type '...'
- Extensions must not contain stored properties
The failure appears to be in Swift Testing’s generated code rather than in my handwritten source.
A representative source file from the repo is:
```swift
import SnapshotTestingMacros
import SwiftUI
import Testing
extension SnapshotTest {
@Suite
@SnapshotSuite()
struct SwiftUIView {
@SnapshotTest()
func swiftUiView() -> some View {
Text("Some SwiftUI text")
}
}
}
```
This is from:
Tests/SnapshotsIntegrationTests/Views/SwiftUI/SwiftUIView.swift
### Reproduction
From the swift-snapshot-testing-macros package:
xcodebuild test \
-parallel-testing-enabled NO \
-scheme SnapshotsIntegrationTests \
-destination 'platform=macOS'
One concrete authored repro file is:
```swift
import SnapshotTestingMacros
import SwiftUI
import Testing
extension SnapshotTest {
@Suite
@SnapshotSuite()
struct SwiftUIView {
@SnapshotTest()
func swiftUiView() -> some View {
Text("Some SwiftUI text")
}
}
}
```
Observed diagnostics in generated source include:
@__swiftmacro_25SnapshotsIntegrationTests12SnapshotTestV11SwiftUIViewV020swiftUiView_snapshotE00E0fMp_.swift:20:24: error: cannot use instance member '...' within property initializer; property initializers
run before 'self' is available
@__swiftmacro_25SnapshotsIntegrationTests12SnapshotTestV11SwiftUIViewV020swiftUiView_snapshotE00E0fMp_.swift:24:1: error: properties with attribute @used must be static
@__swiftmacro_25SnapshotsIntegrationTests12SnapshotTestV11SwiftUIViewV020swiftUiView_snapshotE00E0fMp_.swift:23:2: error: properties with attribute @section must be static
@__swiftmacro_25SnapshotsIntegrationTests12SnapshotTestV11SwiftUIViewV020swiftUiView_snapshotE00E0fMp_.swift:3:98: error: static member 'swiftUiView_snapshotTest' cannot be used on instance of type
'SnapshotTest.SwiftUIView'
I can also reproduce similar failures from other extension/nested suite shapes in the same repo, for example:
- Tests/SnapshotsIntegrationTests/SnapshotTest/Traits/Single/SnapshotTest+Traits+Theme+SwiftUI.swift
- Tests/SnapshotsIntegrationTests/SnapshotTest/Traits/Single/SnapshotTest+Traits+Theme+Inheritance+SwiftUI.swift
### Expected behavior
Swift Testing macro expansion should generate valid Swift for tests inside extension-scoped and nested suite structures, including cases where a consumer macro expands into @Test-annotated members.
The package should compile and run the integration target successfully on Xcode 26.4.
### Environment
Xcode 26.4
Build version 17E192
swift-driver version: 1.148.6 Apple Swift version 6.3 (swiftlang-6.3.0.123.5 clang-2100.0.123.102)
Target: arm64-apple-macosx26.0
Darwin AT-AL1QF6FC 25.2.0 Darwin Kernel Version 25.2.0: Tue Nov 18 21:09:56 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T6041 arm64
### Additional information
Public repo:
https://github.com/adammcarter/swift-snapshot-testing-macros
Regression note:
- this repro worked in Xcode 26.3
- it started failing in Xcode 26.4
In this repo:
- swift build passes
- macro unit tests can be made to pass
- the integration target still fails because Swift Testing-generated @__swiftmacro_*.swift code is invalid
The compiler errors consistently point at generated Swift Testing expansion files rather than authored source. The smallest concrete repro I currently have from the repo is the SwiftUIView example above.
If useful, I can also provide:
- a stripped-down standalone SwiftPM repro
- the failing .xcresult
- the exact generated @__swiftmacro_*.swift snippet from the failing build
0 条评论