Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2025

Conversation

stmontgomery
Copy link
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
Contributor Author

@swift-ci please test

@stmontgomery stmontgomery merged commit 756316c into swiftlang:main Apr 9, 2025
3 checks passed
@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
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