8000 Inconsistent isolation of top-level closure · Issue #81599 · swiftlang/swift · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Inconsistent isolation of top-level closure #81599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sutaner opened this issue May 19, 2025 · 1 comment
Open

Inconsistent isolation of top-level closure #81599

sutaner opened this issue May 19, 2025 · 1 comment
8000
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@sutaner
Copy link
sutaner commented May 19, 2025

Description

It seems that a top-level closure without attributes is interpreted as both @MainActor and non-@MainActor.

Reproduction

enum Something {

    @MainActor static var value = 0

}

let closure: () -> Void = {
    Something.value += 1
}

let sendableClosure: @Sendable () -> Void = {
    closure()
}

See also: https://forums.swift.org/t/why-can-a-sendable-closure-call-a-non-sendable-closure/79921

Expected behavior

The given code compiles (even in language mode 6) although it should not.

Environment

swift-driver version: 1.120.5 Apple Swift version 6.1.2 (swiftlang-6.1.2.1.2 clang-1700.0.13.5)
Target: arm64-apple-macosx15.0

Additional information

No response

@sutaner sutaner added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels May 19, 2025
@rayx
Copy link
rayx commented May 20, 2025

Workaround: declaring closure()'s isolation explicitly helps compiler to catch the issue.

  enum Something {
      @MainActor static var value = 0
  }

- let closure: () -> Void = {
+ let closure: @MainActor () -> Void = {
      Something.value += 1
  }

  let sendableClosure: @Sendable () -> Void = {
      closure() // error: call to main actor-isolated let 'closure' in a synchronous nonisolated context
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

2 participants
0