Did something break SE-0313, or am I missing something?
I am not able to compile the declaration below, neither in Swift 5
mode nor in Swift 6
mode.
let f = BankAccount.deposit (amount:)
// error: Call to actor-isolated instance method 'deposit(amount:)' in a synchronous main actor-isolated context
Context
@main
enum SE_0313 {
static func main () async {
/* From SE-0313 */
// type of f is (isolated BankAccount) -> (Double) -> Void
let f = BankAccount.deposit (amount:)
// error: Call to actor-isolated instance method 'deposit(amount:)' in a synchronous main actor-isolated context
}
}
/* From SE-0313 */
actor BankAccount {
let accountNumber: Int
var balance: Double
init (accountNumber: Int, initialDeposit: Double) {
self.accountNumber = accountNumber
self.balance = initialDeposit
}
func deposit (amount: Double) {
assert(amount >= 0)
balance = balance + amount
}
}
/*
A function can become actor-isolated by indicating that one of its parameters is isolated. For example, the deposit(amount:) operation can now be expressed as a module-scope function as follows:
*/
func deposit (amount: Double, to account: isolated BankAccount) {
assert (amount >= 0)
account.balance = account.balance + amount
}
Note: if BankAccount
were a class the declaration would compile.