|
| 1 | +// RUN: %target-swift-frontend -parse-as-library -emit-sil -verify %s |
| 2 | + |
| 3 | +// Fixtures |
| 4 | + |
| 5 | +@globalActor final actor FirstActor { |
| 6 | + static let shared: FirstActor = FirstActor() |
| 7 | +} |
| 8 | + |
| 9 | +@globalActor final actor SecondActor { |
| 10 | + static let shared: SecondActor = SecondActor() |
| 11 | +} |
| 12 | + |
| 13 | + |
| 14 | +@FirstActor |
| 15 | +func isolatedFunc() {} // expected-note 10{{calls to global function 'isolatedFunc()' from outside of its actor context are implicitly asynchronous}} |
| 16 | + |
| 17 | +class BaseWithNonisolatedDeinit {} |
| 18 | + |
| 19 | +class BaseWithDeinitIsolatedOnFirstActor { |
| 20 | + @FirstActor deinit {} |
| 21 | +} |
| 22 | + |
| 23 | +class BaseWithDeinitIsolatedOnSecondActor { |
| 24 | + @SecondActor deinit {} |
| 25 | +} |
| 26 | + |
| 27 | +// |
| 28 | +// Part 1 - Actors |
| 29 | +// |
| 30 | + |
| 31 | +actor ImplicitDeinitActor { |
| 32 | + // nonisolated deinit |
| 33 | +} |
| 34 | + |
| 35 | +actor ExplicitDeinitActor { |
| 36 | + // self-isolated deinit |
| 37 | + deinit { |
| 38 | + isolatedFunc() // expected-error {{call to global actor 'FirstActor'-isolated global function 'isolatedFunc()' in a synchronous actor-isolated context}} |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +actor NonisolatedDeinitActor { |
| 43 | + // nonisolated deinit |
| 44 | + nonisolated deinit { |
| 45 | + isolatedFunc() // expected-error {{call to global actor 'FirstActor'-isolated global function 'isolatedFunc()' in a synchronous nonisolated context}} |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +actor IsolatedDeinitActor { |
| 50 | + // FirstActor-isolated deinit |
| 51 | + @FirstActor deinit { |
| 52 | + isolatedFunc() // ok |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +// Part 2 - Classes |
| 57 | +// Part 2.1 - Without base class |
| 58 | + |
| 59 | +@FirstActor |
| 60 | +class ImplicitDeinit { |
| 61 | + // nonisolated deinit |
| 62 | +} |
| 63 | + |
| 64 | +@FirstActor |
| 65 | +class ExplicitDeinit { |
| 66 | + // FirstActor-isolated deinit |
| 67 | + deinit { |
| 68 | + isolatedFunc() // ok |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +@FirstActor |
| 73 | +class NonisolatedDeinit { |
| 74 | + // nonisolated deinit |
| 75 | + nonisolated deinit { |
| 76 | + isolatedFunc() // expected-error {{call to global actor 'FirstActor'-isolated global function 'isolatedFunc()' in a synchronous nonisolated context}} |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +class IsolatedDeinit { |
| 81 | + // FirstActor-isolated deinit |
| 82 | + @FirstActor deinit { |
| 83 | + isolatedFunc() // ok |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +@FirstActor |
| 88 | +class DifferentIsolatedDeinit { |
| 89 | + // SecondActor-isolated deinit |
| 90 | + @SecondActor deinit { |
| 91 | + isolatedFunc() // expected-error {{call to global actor 'FirstActor'-isolated global function 'isolatedFunc()' in a synchronous global actor 'SecondActor'-isolated context}} |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +// Part 2.2 - Base class with nonisolated deinit |
| 96 | + |
| 97 | +@FirstActor |
| 98 | +class ImplicitDeinitInheritNonisolated: BaseWithNonisolatedDeinit { |
| 99 | + // nonisolated deinit |
| 100 | +} |
| 101 | + |
| 102 | +@FirstActor |
| 103 | +class ExplicitDeinitInheritNonisolated: BaseWithNonisolatedDeinit { |
| 104 | + // FirstActor-isolated deinit |
| 105 | + deinit { |
| 106 | + isolatedFunc() // ok |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | +@FirstActor |
| 111 | +class NonisolatedDeinitInheritNonisolated: BaseWithNonisolatedDeinit { |
| 112 | + // nonisolated deinit |
| 113 | + nonisolated deinit { |
| 114 | + isolatedFunc() // expected-error {{call to global actor 'FirstActor'-isolated global function 'isolatedFunc()' in a synchronous nonisolated context}} |
| 115 | + } |
| 116 | +} |
| 117 | + |
| 118 | +class IsolatedDeinitInheritNonisolated: BaseWithNonisolatedDeinit { |
| 119 | + // FirstActor-isolated deinit |
| 120 | + @FirstActor deinit { |
| 121 | + isolatedFunc() // ok |
| 122 | + } |
| 123 | +} |
| 124 | + |
| 125 | +@FirstActor |
| 126 | +class DifferentIsolatedDeinitInheritNonisolated: BaseWithNonisolatedDeinit { |
| 127 | + // SecondActor-isolated deinit |
| 128 | + @SecondActor deinit { |
| 129 | + isolatedFunc() // expected-error {{call to global actor 'FirstActor'-isolated global function 'isolatedFunc()' in a synchronous global actor 'SecondActor'-isolated context}} |
| 130 | + } |
| 131 | +} |
| 132 | + |
| 133 | +// Part 2.3 - Base class with isolated deinit |
| 134 | + |
| 135 | +@FirstActor |
| 136 | +class ImplicitDeinitInheritIsolated1: BaseWithDeinitIsolatedOnFirstActor { |
| 137 | + // FirstActor-isolated deinit |
| 138 | +} |
| 139 | + |
| 140 | +@FirstActor |
| 141 | +class ExplicitDeinitIsolated1: BaseWithDeinitIsolatedOnFirstActor { |
| 142 | + // FirstActor-isolated deinit |
| 143 | + deinit { |
| 144 | + isolatedFunc() // ok |
| 145 | + } |
| 146 | +} |
| 147 | + |
| 148 | +@FirstActor |
| 149 | +class NonisolatedDeinitIsolated1: BaseWithDeinitIsolatedOnFirstActor { |
| 150 | + // FirstActor-isolated deinit |
| 151 | + nonisolated deinit { // expected-error {{nonisolated deinitializer 'deinit' has different actor isolation from global actor 'FirstActor'-isolated overridden declaration}} |
| 152 | + isolatedFunc() // expected-error {{call to global actor 'FirstActor'-isolated global function 'isolatedFunc()' in a synchronous nonisolated context}} |
| 153 | + } |
| 154 | +} |
| 155 | + |
| 156 | +class IsolatedDeinitIsolated1: BaseWithDeinitIsolatedOnFirstActor { |
| 157 | + // FirstActor-isolated deinit |
| 158 | + @FirstActor deinit { |
| 159 | + isolatedFunc() // pl |
| 160 | + } |
| 161 | +} |
| 162 | + |
| 163 | +@FirstActor |
| 164 | +class DifferentIsolatedDeinitIsolated1: BaseWithDeinitIsolatedOnFirstActor { |
| 165 | + // error |
| 166 | + @SecondActor deinit { // expected-error {{global actor 'SecondActor'-isolated deinitializer 'deinit' has different actor isolation from global actor 'FirstActor'-isolated overridden declaration}} |
| 167 | + isolatedFunc() // expected-error {{call to global actor 'FirstActor'-isolated global function 'isolatedFunc()' in a synchronous global actor 'SecondActor'-isolated context}} |
| 168 | + } |
| 169 | +} |
| 170 | + |
| 171 | +// Part 2.4 - Base class with isolated deinit with different actor |
| 172 | + |
| 173 | +@FirstActor |
| 174 | +class ImplicitDeinitInheritIsolated2: BaseWithDeinitIsolatedOnSecondActor { |
| 175 | + // SecondActor-isolated deinit |
| 176 | +} |
| 177 | + |
| 178 | +@FirstActor |
| 179 | +class ExplicitDeinitIsolated2: BaseWithDeinitIsolatedOnSecondActor { |
| 180 | + // SecondActor-isolated deinit |
| 181 | + deinit { |
| 182 | + isolatedFunc() // ok |
| 183 | + } |
| 184 | +} |
| 185 | + |
| 186 | +@FirstActor |
| 187 | +class NonisolatedDeinitIsolated2: BaseWithDeinitIsolatedOnSecondActor { |
| 188 | + // SecondActor-isolated deinit |
| 189 | + nonisolated deinit { |
| 190 | + isolatedFunc() // expected-error {{call to global actor 'FirstActor'-isolated global function 'isolatedFunc()' in a synchronous nonisolated context}} |
| 191 | + } |
| 192 | +} |
| 193 | + |
| 194 | +class IsolatedDeinitIsolated2: BaseWithDeinitIsolatedOnSecondActor { |
| 195 | + // // error |
| 196 | + @FirstActor deinit { |
| 197 | + isolatedFunc() // error |
| 198 | + } |
| 199 | +} |
| 200 | + |
| 201 | +@FirstActor |
| 202 | +class DifferentIsolatedDeinitIsolated2: BaseWithDeinitIsolatedOnSecondActor { |
| 203 | + // SecondActor-isolated deinit |
| 204 | + @SecondActor deinit { |
| 205 | + isolatedFunc() // expected-error {{call to global actor 'FirstActor'-isolated global function 'isolatedFunc()' in a synchronous global actor 'SecondActor'-isolated context}} |
| 206 | + } |
| 207 | +} |
| 208 | + |
0 commit comments