Skip to content

Cannot access nonisolated(unsafe) var property of actor from init #73294

@jumhyn-browser

Description

@jumhyn-browser

Description

Accessing a nonisolated(unsafe) var from an actor initializer gives a warning

Reproduction

actor A {
  private nonisolated(unsafe) var child: B!
  init() {
    child = B(parent: self) // warning: cannot access property 'child' here in non-isolated initializer; this is an error in the Swift 6 language mode
  }
}
actor B {
    unowned nonisolated let parent: any Actor

    init(parent: any Actor) {
        self.parent = parent
    }
}

the following workaround compiles without issue:

actor A {
  private nonisolated(unsafe) var child: B!
  init() {
    let b = B(parent: self)
    f(b)
  }

  nonisolated func f(_ b: B) {
    child = b
  }
}
actor B {
    unowned nonisolated let parent: any Actor

    init(parent: any Actor) {
        self.parent = parent
    }
}

Expected behavior

No warning

Environment

Godbolt nightly

Swift version 6.0-dev (LLVM 57699466ce1fb1c, Swift e373cae72967b82)
Target: x86_64-unknown-linux-gnu

Additional information

No response

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.concurrencyFeature: umbrella label for concurrency language features

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions