Skip to content

Conversation

@grynspan
Copy link
Contributor

@grynspan grynspan commented Jul 7, 2025

This PR prevents @Test from being applied to an operator declaration such as:

@Test(arguments: ...)
static func +(lhs: A, rhs: B) { ... }

Now, the following error will be emitted by the compiler:

🛑 Attribute 'Test' cannot be applied to an operator

Previously, applying @Test to an operator produced undefined/unstable effects.

Resolves #1204.

Checklist:

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

This PR prevents `@Test` from being applied to an operator declaration such as:

```swift
@test(arguments: ...)
static func +(lhs: A, rhs: B) { ... }
```

Now, the following error will be emitted by the compiler:

> 🛑 Attribute 'Test' cannot be applied to an operator

Previously, applying `@Test` to an operator produced undefined/unstable effects.

Resolves #1204.
@grynspan grynspan added this to the Swift 6.x (main) milestone Jul 7, 2025
@grynspan grynspan self-assigned this Jul 7, 2025
@grynspan grynspan added bug 🪲 Something isn't working macros 🔭 Related to Swift macros such as @Test or #expect labels Jul 7, 2025
@grynspan
Copy link
Contributor Author

grynspan commented Jul 7, 2025

@swift-ci test

@grynspan grynspan merged commit 5fd38df into main Jul 7, 2025
3 checks passed
@grynspan grynspan deleted the jgrynspan/1204-block-operators-as-test-decls branch July 7, 2025 16:24
grynspan added a commit that referenced this pull request Jul 7, 2025
This PR prevents `@Test` from being applied to an operator declaration
such as:

```swift
@test(arguments: ...)
static func +(lhs: A, rhs: B) { ... }
```

Now, the following error will be emitted by the compiler:

> 🛑 Attribute 'Test' cannot be applied to an operator

Previously, applying `@Test` to an operator produced undefined/unstable
effects.

Resolves #1204.

### 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.
grynspan added a commit that referenced this pull request Jul 8, 2025
- **Explanation**: Block `@Test` on operator declarations, which doesn't
work correctly and was never supported.
- **Scope**: Attempting to declare `@Test func +()`.
- **Issues**: #1204
- **Original PRs**: #1205
- **Risk**: Low (this was never supported)
- **Testing**: New test case added.
- **Reviewers**: @stmontgomery @briancroom
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.

@Test doesn't work consistently on operator functions

3 participants