Skip to content

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Apr 8, 2024

This PR applies all suite diagnostics* to every decl group (declaring type or extension) in the lexical context during @Suite and @Test expansion. For example:

struct S1<T> {
  @Suite struct S2 { // 🛑 Attribute 'Suite' cannot be applied to a generic structure
    @Test func f() {} // 🛑 Attribute 'Test' cannot be applied to a generic function
  }
}

This PR is follow-up to #332 and #333.

* Except for diagnostics specific to the @Suite attribute itself.

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 applies all suite diagnostics\* to every decl group (declaring type or
extension) in the lexical context during `@Suite` and `@Test` expansion. For
example:

```swift
struct S1<T> {
  @suite struct S2 { // 🛑 Attribute 'Suite' cannot be applied to a generic structure
    @test func f() {} // 🛑 Attribute 'Test' cannot be applied to a generic function
  }
}
```

This PR is follow-up to #332 and #333.

\* Except for diagnostics specific to the `@Suite` attribute itself.
@grynspan grynspan added bug 🪲 Something isn't working swift-6 labels Apr 8, 2024
@grynspan grynspan self-assigned this Apr 8, 2024
@@ -189,7 +189,7 @@ struct DiagnosticMessage: SwiftDiagnostics.DiagnosticMessage {
/// - Returns: A diagnostic message.
static func genericDeclarationNotSupported(_ decl: some SyntaxProtocol, whenUsing attribute: AttributeSyntax, becauseOf genericClause: some SyntaxProtocol) -> Self {
Self(
syntax: Syntax(genericClause),
syntax: (genericClause.root != decl.root) ? Syntax(decl) : Syntax(genericClause),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nodes from the lexical context are detached, so diagnostics applied to them don't align to any real source location. This check is only (currently) needed here since we use this diagnostic unmodified for both code paths and prefer that the diagnostic point to the generic clause rather than the affected symbol.

@grynspan
Copy link
Contributor Author

grynspan commented Apr 8, 2024

@swift-ci please test

@grynspan
Copy link
Contributor Author

grynspan commented Apr 8, 2024

@swift-ci please test

@grynspan
Copy link
Contributor Author

grynspan commented Apr 8, 2024

@swift-ci please test

@grynspan grynspan merged commit 948b59d into main Apr 9, 2024
@grynspan grynspan deleted the jgrynspan/apply-suite-diagnostics-to-lexical-context branch April 9, 2024 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants