Skip to content

Commit 756316c

Browse files
authored
Fully-qualify reference to Swift's Actor protocol in macro expansion code for synchronous test functions (#1067)
This fixes a compilation error in code expanded from the `@Test` macro when it's attached to a synchronous (i.e. non-`async`) test function in a context where there is a concrete type named `Actor`. For example, the following code reproduces the error: ```swift // In MyApp public class Actor {} // In test code import Testing import MyApp // ❌ 'any' has no effect on concrete type 'Actor' // - 'isolated' parameter type 'Actor?' does not conform to 'Actor' or 'DistributedActor' @test func example() /* No 'async' */ {} ``` The macro code includes an unqualified reference to a type by that name, but it's intended to refer to the protocol in Swift's `_Concurrency` module. The fix is to ensure the macro's reference to this protocol is fully-qualified with a module name. This was first reported on the Swift Forums in https://forums.swift.org/t/error-isolated-parameter-type-actor-does-not-conform-to-actor-or-distributedactor/79190. This bug was introduced in #747, which first landed in Swift 6.1 and Xcode 16.3. ### 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 6cf0110 commit 756316c

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Sources/TestingMacros/TestDeclarationMacro.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ public struct TestDeclarationMacro: PeerMacro, Sendable {
328328
}
329329
FunctionParameterSyntax(
330330
firstName: .wildcardToken(),
331-
type: "isolated (any Actor)?" as TypeSyntax,
331+
type: "isolated (any _Concurrency.Actor)?" as TypeSyntax,
332332
defaultValue: InitializerClauseSyntax(value: "Testing.__defaultSynchronousIsolationContext" as ExprSyntax)
333333
)
334334
}

Tests/TestingTests/MiscellaneousTests.swift

+5
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ struct SendableTests: Sendable {
139139
@Suite("Named Sendable test type", .hidden)
140140
struct NamedSendableTests: Sendable {}
141141

142+
// This is meant to help detect unqualified usages of the `Actor` protocol from
143+
// Swift's `_Concurrency` module in macro expansion code, since it's possible
144+
// for another module to declare a type with that name.
145+
private class Actor {}
146+
142147
#if !SWT_NO_GLOBAL_ACTORS
143148
@Suite(.hidden)
144149
@MainActor

0 commit comments

Comments
 (0)