Skip to content

Diagnose the use of a generic clause on @Test, @Suite, and @Tag.#1650

Merged
grynspan merged 2 commits into
mainfrom
jgrynspan/diagnose-generic-clause-on-test-attribute
Apr 1, 2026
Merged

Diagnose the use of a generic clause on @Test, @Suite, and @Tag.#1650
grynspan merged 2 commits into
mainfrom
jgrynspan/diagnose-generic-clause-on-test-attribute

Conversation

@grynspan

@grynspan grynspan commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

For example:

@Test<[Int]>(arguments: [1, 2, 3]) func f(i: Int) { ... }

We never intended for this to be valid syntax. It appears some folks are using it, so deprecate for now and make it an error in the next language mode. The diagnostic looks like this in the Swift 6 language mode:

⚠️ Generic argument clause of attribute 'Test' is unsupported; this is an error in the Swift 7 language mode

And in the Swift 7 language mode, it's an error. (In the future, if we find that this syntax is useful and want to build out some sort of support for it, we can of course remove the diagnostic.)

Checklist:

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

For example:

```swift
@test<[Int]>(arguments: [1, 2, 3]) func f(i: Int) { ... }
```

We never intended for this to be valid syntax. It appears some folks _are_ using it, so deprecate for now and make it an error in the next language mode.
@grynspan grynspan added this to the Swift 6.4.0 (main) milestone Mar 31, 2026
@grynspan grynspan self-assigned this Mar 31, 2026
@grynspan grynspan requested a review from stmontgomery as a code owner March 31, 2026 16:16
@grynspan grynspan added the bug 🪲 Something isn't working label Mar 31, 2026
@grynspan grynspan added the macros 🔭 Related to Swift macros such as @Test or #expect label Mar 31, 2026
Comment thread Sources/TestingMacros/Support/DiagnosticMessage.swift
Comment thread Tests/TestingTests/EventIterationTests.swift Outdated
@grynspan grynspan requested a review from harlanhaskins March 31, 2026 16:53
@grynspan grynspan merged commit 056b7fd into main Apr 1, 2026
27 checks passed
@grynspan grynspan deleted the jgrynspan/diagnose-generic-clause-on-test-attribute branch April 1, 2026 16:31
grynspan added a commit that referenced this pull request Apr 1, 2026
#1650)

For example:

```swift
@test<[Int]>(arguments: [1, 2, 3]) func f(i: Int) { ... }
```

We never intended for this to be valid syntax. It appears some folks
_are_ using it, so deprecate for now and make it an error in the next
language mode. The diagnostic looks like this in the Swift 6 language
mode:

> ⚠️ Generic argument clause of attribute 'Test' is unsupported; this is
an error in the Swift 7 language mode

And in the Swift 7 language mode, it's an error. (In the future, if we
find that this syntax is useful and want to build out some sort of
support for it, we can of course remove the diagnostic.)

### 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 Apr 1, 2026
…d `@Tag`. (#1653)

- **Explanation**: Disallow (warn) the use of the generic clause syntax
on our attribute macros as we never intended for them to work and they
are not handled by the macro expansions.
- **Scope**: Macro expansion
- **Issues**: N/A
- **Original PRs**: #1650
- **Risk**: Low (adds a warning)
- **Testing**: New unit test
- **Reviewers**: @stmontgomery @harlanhaskins
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.

3 participants