Skip to content

Different sending behavior between global actor and isolated parameter within a closure #75910

Description

@mattmassicotte

Description

I'm trying to understand the difference between these two forms. I think they should be equivalent, but the global actor version works and the isolation param version does not.

Reproduction

class Argument {
}

class NonSendable {
    public func noArgument(closure: () -> Void) {
    }
    
    public func isolatedNoArgument(isolation: isolated (any Actor)? = #isolation, value: Argument) {
        noArgument() {
            Task {
                _ = isolation
                
                // ERROR: Sending 'value' risks causing data races
                print(value)
            }
        }
    }
    
    @MainActor
    public func globalActorArgument(value: Argument) {
        noArgument() {
            Task {
                print(value)
            }
        }
    }
}

Expected behavior

I expected both of these versions to compile with no error.

Environment

Apple Swift version 6.0-dev (LLVM 3751470251df3e4, Swift 026ffdd)
Target: arm64-apple-macosx14.0

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    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