Skip to content

@isolated(any) closure can be assigned to non isolated closure property #80823

Closed
@ricocrescenzio95

Description

@ricocrescenzio95

Description

The compiler allows to set an @isolated(any) closure to a property that is not isolated itself. Shouldn't this throw a compilation error?

struct Example {
  var getString: @Sendable () -> String

  init(getString: @isolated(any) @escaping @Sendable () -> String) {
    self.getString = getString
  }
}

Reproduction

struct Example {
  var getString: @Sendable () -> String

  init(getString: @isolated(any) @escaping @Sendable () -> String) {
    self.getString = getString
  }
}

await Task.detached {
  let e = Example { @MainActor in
    MainActor.assertIsolated() // This crashes
    return "Hello, world!"
  }
  print(e.getString())
}.value

Expected behavior

The compiler should not allow self.getString = getString, unless var getString: @Sendable () -> String is changed to var getString: @isolated(any) @Sendable () -> String.

Environment

swift-driver version: 1.120.5 Apple Swift version 6.1 (swiftlang-6.1.0.110.21 clang-1700.0.13.3)
Target: arm64-apple-macosx15.0

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions