Skip to content

Commit 91f7889

Browse files
authored
Work around compiler bug affecting macro decls with #if-guarded availability when building w/legacy driver (#1106)
This works around a Swift compiler bug which causes a failure validating the generated .swiftinterface of the `Testing` module due to it having macro declarations with `#if`-conditionalized `@available(...)` attributes _before_ any other `@`-attributes. The PR which recently landed to enable the Exit Tests feature (#324) revealed this compiler bug — specifically, that PR removed `@_spi` attributes which until then _preceded_ `#if SWT_NO_EXIT_TESTS`. The workaround is to move other attributes on the affected macro declarations up before the `#if`. The compiler bug is being fixed in swiftlang/swift#81346. It only appears to happen when building with the legacy driver, and Android uses that driver still. An example CI failure log can be found here: > https://github.com/thebrowsercompany/swift-build/actions/runs/14823859186/job/41615678071#step:32:72 ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent 6e4fe1f commit 91f7889

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Sources/Testing/Expectations/Expectation+Macro.swift

+6-4
Original file line numberDiff line numberDiff line change
@@ -514,11 +514,12 @@ public macro require<R>(
514514
/// @Metadata {
515515
/// @Available(Swift, introduced: 6.2)
516516
/// }
517+
@freestanding(expression)
518+
@discardableResult
517519
#if SWT_NO_EXIT_TESTS
518520
@available(*, unavailable, message: "Exit tests are not available on this platform.")
519521
#endif
520-
@discardableResult
521-
@freestanding(expression) public macro expect(
522+
public macro expect(
522523
processExitsWith expectedExitCondition: ExitTest.Condition,
523524
observing observedValues: [any PartialKeyPath<ExitTest.Result> & Sendable] = [],
524525
_ comment: @autoclosure () -> Comment? = nil,
@@ -559,11 +560,12 @@ public macro require<R>(
559560
/// @Metadata {
560561
/// @Available(Swift, introduced: 6.2)
561562
/// }
563+
@freestanding(expression)
564+
@discardableResult
562565
#if SWT_NO_EXIT_TESTS
563566
@available(*, unavailable, message: "Exit tests are not available on this platform.")
564567
#endif
565-
@discardableResult
566-
@freestanding(expression) public macro require(
568+
public macro require(
567569
processExitsWith expectedExitCondition: ExitTest.Condition,
568570
observing observedValues: [any PartialKeyPath<ExitTest.Result> & Sendable] = [],
569571
_ comment: @autoclosure () -> Comment? = nil,

0 commit comments

Comments
 (0)