Files
swift-mirror/test/Concurrency/async_let_isolation.swift
2021-05-06 22:18:36 -07:00

35 lines
835 B
Swift

// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency
// REQUIRES: concurrency
actor MyActor {
let immutable: Int = 17
var text: [String] = []
func synchronous() -> String { text.first ?? "nothing" }
func asynchronous() async -> String { synchronous() }
func testAsyncLetIsolation() async {
async let x = self.synchronous()
async let y = await self.asynchronous()
async let z = synchronous()
var localText = text
async let w = localText.removeLast() // expected-error{{mutation of captured var 'localText' in concurrently-executing code}}
_ = await x
_ = await y
_ = await z
_ = await w
}
}
func outside() async {
let a = MyActor()
async let x = a.synchronous() // okay, await is implicit
async let y = await a.synchronous()
_ = await x
_ = await y
}