'isolated' parameter has non-actor type 'Self'

this compiles:

actor A 
{
    init() {}
}
extension A 
{
    nonisolated
    func f() async
    {
        await { (self:isolated A) in } (self)
    }
}

yet this does not:

actor A 
{
    init() {}
}
extension A 
{
    nonisolated
    func f() async
    {
-       await { (self:isolated A) in } (self)
+       await { (self:isolated Self) in } (self)
    }
}
error: 'isolated' parameter has non-actor type 'Self'

why?

1 Like

The Distributed module actually uses such code so I'm surprised this is failing for you.

It is also not reproducing on main in the Swift repo -- nor in the Xcode I had at hand.

Where exactly is this failing (versions)?

i’m using the latest swift (5.9.2)

$ swiftc test.swift 
test.swift:10:23: error: 'isolated' parameter has non-actor type 'Self'
        await { (self:isolated Self) in } (self)
                      ^
error: fatalError
$ swiftc --version
Swift version 5.9.2 (swift-5.9.2-RELEASE)
Target: x86_64-unknown-linux-gnu

i’m not using XCode, i’m using VSCode, but i doubt this is related to the IDE. i get the same error when i try it on godbolt.

Okey managed to reproduce, I wonder why I didn't last evening.

Worth filing a bug imho, would you mind? GitHub - apple/swift: The Swift Programming Language

done

1 Like

Thanks, fix here: [Concurrency] allow isolated on dynamic self types by ktoso Β· Pull Request #70925 Β· apple/swift Β· GitHub

2 Likes

wow, that was fast! thanks!

1 Like

Yep, thanks.

Sadly it turns out nothing is ever that simple, and here's a follow up about handling self properly: [Concurrency] isolated fixes; ban Array<T> and handle Self in actor by ktoso Β· Pull Request #70955 Β· apple/swift Β· GitHub

Making it just workβ„’ always would require an evolution proposal it seems.

1 Like