Skip to content

Add an attribute that emits a warning. #895

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 2 commits into from
Jan 7, 2025
Merged

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Jan 7, 2025

This PR adds an attribute (an overload of @__testing()) that emits a warning. This allows us to emit compile-time warnings from contexts where only attributes are semantically valid.

We need this in particular for test content records because their section info is comprised of a big IfConfigDecl node and platforms that aren't covered (i.e. the #else clause) don't have a way to emit a diagnostic that says "we need to fix this platform's Swift Testing port!" like we can do in other contexts with #warning():

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
@_section("__DATA_CONST,__swift5_tests")
#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(Android) || os(WASI)
@_section("swift5_tests")
#elseif os(Windows)
@_section(".sw5test$B")
#else
// ⚠️ #warning isn't valid here, what do we do!?
#endif
@_used
private static let record: __TestContentRecord = (...)

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 adds an attribute (an overload of `@__testing()`) that emits a warning.
This allows us to emit compile-time warnings from contexts where only attributes
are semantically valid.

We need this in particular for test content records because their section info
is comprised of a big `IfConfigDecl` node and platforms that aren't covered
(i.e. the `#else` clause) don't have a way to emit a diagnostic that says "we
need to fix this platform's Swift Testing port!" like we can do in other
contexts with `#warning()`:

```swift
@_section("__DATA_CONST,__swift5_tests")
@_section("swift5_tests")
@_section(".sw5test$B")
// ⚠️ #warning isn't valid here, what do we do!?
@_used
private static let record: __TestContentRecord = (...)
```
@grynspan grynspan added enhancement New feature or request workaround Workaround for an issue in another component (may need to revert later) build 🧱 Affects the project's build configuration or process labels Jan 7, 2025
@grynspan grynspan added this to the Swift 6.x milestone Jan 7, 2025
@grynspan grynspan self-assigned this Jan 7, 2025
@grynspan
Copy link
Contributor Author

grynspan commented Jan 7, 2025

@swift-ci test

@grynspan
Copy link
Contributor Author

grynspan commented Jan 7, 2025

@swift-ci test

@grynspan grynspan merged commit 6f7688a into main Jan 7, 2025
3 checks passed
@grynspan grynspan deleted the jgrynspan/warning-attribute branch January 7, 2025 19:05
@grynspan grynspan added the discovery 🔎 test content discovery label Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build 🧱 Affects the project's build configuration or process discovery 🔎 test content discovery enhancement New feature or request workaround Workaround for an issue in another component (may need to revert later)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants