Skip to content

[Sema] Clarify diagnostic for type attributes only valid in inheritance clauses#88585

Open
qflen wants to merge 1 commit intoswiftlang:mainfrom
qflen:fix-preconcurrency-inheritance-diagnostic
Open

[Sema] Clarify diagnostic for type attributes only valid in inheritance clauses#88585
qflen wants to merge 1 commit intoswiftlang:mainfrom
qflen:fix-preconcurrency-inheritance-diagnostic

Conversation

@qflen
Copy link
Copy Markdown

@qflen qflen commented Apr 21, 2026

Fixes #88338.

The shared diagnostic typeattr_not_inheritance_clause fires for @unchecked, @preconcurrency, @unsafe, and @nonisolated when used as a type attribute outside an inheritance clause. The old wording, "%0 only applies in inheritance clauses", reads as a universal claim about the attribute, but all four have valid declaration-attribute uses elsewhere (imports, funcs, etc.).

Reworded to "%0 can only be used as a type attribute in inheritance clauses" so the error scopes itself to the type-attribute form.

Changes

  • include/swift/AST/DiagnosticsSema.def: updated diagnostic text.
  • test/Concurrency/preconcurrency_conformances.swift: updated 4 expectations, added a regression test for the reporter's repro (let _: @preconcurrency @MainActor () -> Void = {}).
  • test/Concurrency/concurrent_value_checking_typechecker_errors.swift: updated 2 expectations.

No logic changes. The @retroactive sibling diagnostic is unchanged since its wording is already scoped correctly.

…ce clauses

The shared diagnostic for @unchecked, @preconcurrency, @unsafe, and
@nonisolated used in an invalid type-attribute position read "only
applies in inheritance clauses", which is misleading since all four
have valid declaration-attribute uses elsewhere (imports, funcs, etc.).

Reword to "can only be used as a type attribute in inheritance clauses"
so the error scopes itself to the type-attribute form.

Fixes swiftlang#88338.
@qflen qflen requested a review from a team as a code owner April 21, 2026 16:21
@qflen
Copy link
Copy Markdown
Author

qflen commented Apr 22, 2026

For reviewer context: #88356 (Apr 8) also addresses #88338 with a similar test-expectation update but a different wording choice: "attribute '%0' cannot be applied to a type".

I landed on "%0 can only be used as a type attribute in inheritance clauses" because @preconcurrency (and the sibling attributes) can be applied to types in inheritance clauses, so the "cannot be applied to a type" framing loses the scope the original reporter was asking for. This PR also adds a regression test for the reporter's exact repro. Happy to defer either way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error says @preconcurrency only applies in inheritance clauses

1 participant