forked from swiftlang/swift
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasync_let_isolation.swift
55 lines (41 loc) · 1.69 KB
/
async_let_isolation.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// First without any concurrency enabled.
// RUN: %target-swift-frontend -target %target-swift-5.1-abi-triple %s -emit-sil -o /dev/null -verify -verify-additional-prefix without-transferring-
// Then with targeted.
// RUN: %target-swift-frontend -target %target-swift-5.1-abi-triple %s -emit-sil -o /dev/null -verify -strict-concurrency=targeted -verify-additional-prefix without-transferring-
// Then strict-concurrency with everything.
// RUN: %target-swift-frontend -target %target-swift-5.1-abi-triple %s -emit-sil -o /dev/null -verify -strict-concurrency=complete -verify-additional-prefix tns-
// REQUIRES: concurrency
// REQUIRES: asserts
actorMyActor{
letimmutable:Int=17
vartext:[String]=[]
func synchronous()->String{ text.first ??"nothing"}
func asynchronous()async->String{synchronous()}
func testAsyncLetIsolation()async{
asyncletx=self.synchronous()
asynclety=awaitself.asynchronous()
asyncletz=synchronous()
varlocalText= text
asyncletw= localText.removeLast() // expected-without-transferring-warning {{mutation of captured var 'localText' in concurrently-executing code}}
_ =await x
_ =await y
_ =await z
_ =await w
}
}
finalclassMyFinalActor{
letimmutable:Int=17
vartext:[String]=[]
func testAsyncLetIsolation()async{
varlocalText= text
asyncletw= localText.removeLast() // expected-without-transferring-warning {{mutation of captured var 'localText' in concurrently-executing code}}
_ =await w
}
}
func outside()async{
leta=MyActor()
asyncletx= a.synchronous() // okay, await is implicit
asynclety=await a.synchronous()
_ =await x
_ =await y
}