Skip to content

Inconsistent isolation of top-level closure #81599

Open
@sutaner

Description

@sutaner

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

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