Skip to content

#isolation macro unexpectedly nil in nonisolated(nonsending) closures #84171

@jamieQ

Description

@jamieQ

Description

see title

Reproduction

// swiftc -swift-version 6 -enable-upcoming-feature NonisolatedNonsendingByDefault -parse-as-library

actor MyActor {
    // can also remove the explicit nonisolated(nonsending)
    func test(_ closure: nonisolated(nonsending) () async -> Void) async {
        await closure()
    }
}

@concurrent
nonisolated func test() async {
    let a = MyActor()

    await a.test {
        a.assertIsolated() // passes
        let iso = #isolation
        print(iso as Any)  // nil
    }
}

@main
enum App {
    static func main() async {
        await test()
    }
}

Expected behavior

the #isolation macro should resolve to the calling actor when used in a nonisolated(nonsending) closure.

Environment

Swift version 6.2-dev (LLVM 1b5a5a47cc92b04, Swift 7ec75e9)
Target: x86_64-unknown-linux-gnu

Additional information

original forum discussion: https://forums.swift.org/t/isolation-not-providing-the-correct-actor-in-closures-when-nonisolatednonsendingbydefault-is-enabled/81924

godbolt example: https://swift.godbolt.org/z/M5Tzxvhz1

Metadata

Metadata

Assignees

No one assigned

    Labels

    actor isolationFeature → concurrency: Actor isolationbugA 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