Function called isolated on MainActor via an isolated parameter are not considered run on the MainActor

If I try to compile the following, I get a compilation error:

import Foundation

func isolatedPrint<A : Actor>(on actor: isolated A) {
   print("hello")
}

Task{ @MainActor in
   isolatedPrint(on: MainActor.shared)
}

The error:

toto.swift:9:2: error: expression is 'async' but is not marked with 'await'
        isolatedPrint(on: MainActor.shared)
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        await 
toto.swift:9:2: note: calls to global function 'isolatedPrint(on:)' from outside of its actor context are implicitly asynchronous
        isolatedPrint(on: MainActor.shared)
        ^

I don’t understand why the compiler does not detect the function is called on the MainActor via the actor parameter.

I think the droid you’re looking for here is SE-0420 Inheritance of actor isolation, which is only available in the (pre-release) Swift 6 compiler.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Function called isolated on MainActor via an isolated parameter are not considered run on the MainActor
 
 
Q