Error when referencing an actor’s method’s type

Extract from SE-0313 (actor-isolation control):

This makes instance methods on actor types less special, because now they are expressible in terms of a general feature: they are methods for which the self parameter is isolated, which one can see when referencing the method's curried type:

let fn = BankAccount.deposit(amount:) // type of fn is (isolated BankAccount) -> (Double) -> Void

Trying the above piece of code produces the following error.

let g = ActorType.f (i:) // Error: Call to actor-isolated instance method 'f(i:)' in a synchronous main actor-isolated context

But, there is no such error if the type is class:

let f = ClassType.f (i:) // Okay
Details
@main
enum TypeOfFunction {
    static func main () async throws {
        let f = ClassType.f (i:) // Okay
        print ("type of class function is", type (of: f))
        
        let g = ActorType.f (i:) // Error: Call to actor-isolated instance method 'f(i:)' in a synchronous main actor-isolated context
        print ("type of actor function is", type (of: g))
    }
}

actor ActorType {
    func f (i: Int) -> Int {I}
}

class ClassType {
    func f (i: Int) -> Int {I}
}

Can anyone shed some light on this?

This is the same as #85718. It has been fixed on nightly build.

1 Like