Skip to content

Fully-qualify reference to Swift's Actor protocol in macro expansion code for synchronous test functions#1067

Merged
stmontgomery merged 1 commit into
swiftlang:mainfrom
stmontgomery:actor-disambiguation
Apr 9, 2025
Merged

Fully-qualify reference to Swift's Actor protocol in macro expansion code for synchronous test functions#1067
stmontgomery merged 1 commit into
swiftlang:mainfrom
stmontgomery:actor-disambiguation

Conversation

@stmontgomery

Copy link
Copy Markdown
Contributor

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:

// 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:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

@stmontgomery stmontgomery added bug 🪲 Something isn't working macros 🔭 Related to Swift macros such as @Test or #expect labels Apr 9, 2025
@stmontgomery stmontgomery added this to the Swift 6.x milestone Apr 9, 2025
@stmontgomery stmontgomery self-assigned this Apr 9, 2025
@stmontgomery

Copy link
Copy Markdown
Contributor Author

@swift-ci please test

@stmontgomery stmontgomery merged commit 756316c into swiftlang:main Apr 9, 2025
@stmontgomery stmontgomery deleted the actor-disambiguation branch April 9, 2025 18:03
stmontgomery added a commit to stmontgomery/swift-testing that referenced this pull request Apr 11, 2025
…n code for synchronous test functions (swiftlang#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 swiftlang#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.
stmontgomery added a commit to stmontgomery/swift-testing that referenced this pull request Apr 11, 2025
…n code for synchronous test functions (swiftlang#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 swiftlang#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.
stmontgomery added a commit that referenced this pull request Apr 11, 2025
…o expansion code for synchronous test functions (#1071)

- **Explanation**: 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`.
- **Scope**: Affects tests in code which also has a custom type named
`Actor`.
  - **Issues**: n/a
- **Original PRs**: #1067
  - **Risk**: Low
  - **Testing**: Modified tests to detect this.
  - **Reviewers**: @grynspan
stmontgomery added a commit that referenced this pull request Apr 11, 2025
…o expansion code for synchronous test functions (#1072)

- **Explanation**: 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`.
- **Scope**: Affects tests in code which also has a custom type named
`Actor`.
  - **Issues**: n/a
- **Original PRs**: #1067
  - **Risk**: Low
  - **Testing**: Modified tests to detect this.
  - **Reviewers**: @grynspan
@stmontgomery stmontgomery modified the milestones: Swift 6.x, Swift 6.2 Apr 24, 2025
@swiftlang swiftlang deleted a comment Aug 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🪲 Something isn't working macros 🔭 Related to Swift macros such as @Test or #expect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants