swiftlang/swift

Misleading error about `nonisolated` not being applicable to mutable stored properties

Open

#88.709 geöffnet am 28. Apr. 2026

Auf GitHub ansehen
 (2 Kommentare) (0 Reaktionen) (1 zugewiesene Person)Swift (10.719 Forks)batch import
actor isolationcompilerconcurrencydiagnostics qualitygood first issueswift 6.3type checker

Repository-Metriken

Stars
 (69.989 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 7T 6h) (556 gemergte PRs in 30 T)

Beschreibung

Description

No response

Reproduction

@MainActor
final class C {
  nonisolated var c = 0
}
actor A {
  nonisolated var a = 0
}
@MainActor
struct S {
  nonisolated var s = 0
}
<source>:3:3: error: 'nonisolated' cannot be applied to mutable stored properties
 1 | @MainActor
 2 | final class C {
 3 |   nonisolated var c = 0
   |   |               `- note: convert 'c' to a 'let' constant or consider declaring it 'nonisolated(unsafe)' if manually managing concurrency safety
   |   `- error: 'nonisolated' cannot be applied to mutable stored properties
 4 | }
 5 | actor A {

<source>:6:3: error: 'nonisolated' cannot be applied to mutable stored properties
 4 | }
 5 | actor A {
 6 |   nonisolated var a = 0
   |   |               `- note: convert 'a' to a 'let' constant or consider declaring it 'nonisolated(unsafe)' if manually managing concurrency safety
   |   `- error: 'nonisolated' cannot be applied to mutable stored properties
 7 | }
 8 | @MainActor

Expected behavior

'nonisolated' cannot be applied to mutable stored properties

Yes it can — see s. The message needs to be more specific.

Environment

Swift version 6.4-dev (f4c024ed196fc27)

Additional information

No response

Contributor Guide