You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Check inferred isolation for overridden decls from ObjC.
238
+
// Note that even if the override is not present, it
239
+
// can have an affect. -- rdar://87217618 / SR-15694
240
+
@MainActor
241
+
classFooFrame:PictureFrame{
242
+
init(){
243
+
super.init(size:0)
244
+
}
245
+
246
+
overrideinit(size n:Int){
247
+
super.init(size: n)
248
+
}
249
+
250
+
overridefunc rotate(){
251
+
mainActorFn()
252
+
}
253
+
}
254
+
255
+
classBarFrame:PictureFrame{
256
+
init(){
257
+
super.init(size:0)
258
+
}
259
+
260
+
overrideinit(size n:Int){
261
+
super.init(size: n)
262
+
}
263
+
264
+
overridefunc rotate(){
265
+
mainActorFn()
266
+
}
267
+
}
268
+
269
+
@SomeGlobalActor
270
+
classBazFrame:NotIsolatedPictureFrame{
271
+
init(){
272
+
super.init(size:0)
273
+
}
274
+
275
+
overrideinit(size n:Int){
276
+
super.init(size: n)
277
+
}
278
+
279
+
overridefunc rotate(){
280
+
sgActorFn()
281
+
}
282
+
}
283
+
284
+
@SomeGlobalActor
285
+
classBazFrameIso:PictureFrame{ // expected-error {{global actor 'SomeGlobalActor'-isolated class 'BazFrameIso' has different actor isolation from main actor-isolated superclass 'PictureFrame'}}
@SomeGlobalActorfunconions(){} // expected-note{{calls to global function 'onions()' from outside of its actor context are implicitly asynchronous}}
406
+
@SomeGlobalActorfunconions_sga(){} // expected-note 2{{calls to global function 'onions_sga()' from outside of its actor context are implicitly asynchronous}}
407
407
408
408
@available(SwiftStdlib 5.1,*)
409
-
@MainActorfuncbeets(){onions()} // expected-error{{call to global actor 'SomeGlobalActor'-isolated global function 'onions()' in a synchronous main actor-isolated context}}
410
-
// expected-note@-1{{calls to global function 'beets()' from outside of its actor context are implicitly asynchronous}}
409
+
@MainActorfuncbeets_ma(){onions_sga()} // expected-error{{call to global actor 'SomeGlobalActor'-isolated global function 'onions_sga()' in a synchronous main actor-isolated context}}
410
+
// expected-note@-1 4{{calls to global function 'beets_ma()' from outside of its actor context are implicitly asynchronous}}
411
411
412
412
@available(SwiftStdlib 5.1,*)
413
413
actorCrystal{
@@ -942,7 +942,7 @@ class SomeClassWithInits {
942
942
deinit{
943
943
print(mutableState) // Okay, we're actor-isolated
944
944
print(SomeClassWithInits.shared) // expected-error{{static property 'shared' isolated to global actor 'MainActor' can not be referenced from this synchronous context}}
945
-
beets() //expected-error{{call to main actor-isolated global function 'beets()' in a synchronous nonisolated context}}
945
+
beets_ma() //expected-error{{call to main actor-isolated global function 'beets_ma()' in a synchronous nonisolated context}}
946
946
}
947
947
948
948
func isolated(){}
@@ -1384,3 +1384,68 @@ actor DunkTracker {
1384
1384
}
1385
1385
}
1386
1386
}
1387
+
1388
+
@MainActor
1389
+
classMA{
1390
+
func method(){}
1391
+
}
1392
+
1393
+
@SomeGlobalActorclassSGA:MA{} // expected-error {{global actor 'SomeGlobalActor'-isolated class 'SGA' has different actor isolation from main actor-isolated superclass 'MA'}}
// try to override a MA method with inferred isolation from a protocol requirement
1400
+
classSGA_MA:MA,SGA_Proto{
1401
+
// expected-error@+2 {{call to global actor 'SomeGlobalActor'-isolated global function 'onions_sga()' in a synchronous main actor-isolated context}}
1402
+
// expected-warning@+1 {{instance method 'method()' isolated to global actor 'MainActor' can not satisfy corresponding requirement from protocol 'SGA_Proto' isolated to global actor 'SomeGlobalActor'}}
1403
+
overridefunc method(){onions_sga()}
1404
+
}
1405
+
1406
+
classNone_MA:MA{
1407
+
overridefunc method(){beets_ma()}
1408
+
}
1409
+
1410
+
classNone{
1411
+
func method(){} // expected-note{{overridden declaration is here}}
1412
+
}
1413
+
1414
+
// try to add inferred isolation while overriding
1415
+
@MainActor
1416
+
classMA_None1:None{
1417
+
// FIXME: bad note, since the problem is a mismatch in overridden vs inferred isolation; this wont help.
1418
+
// expected-note@+1 {{add '@MainActor' to make instance method 'method()' part of global actor 'MainActor'}}
1419
+
overridefunc method(){
1420
+
beets_ma() // expected-error {{call to main actor-isolated global function 'beets_ma()' in a synchronous nonisolated context}}
1421
+
}
1422
+
}
1423
+
1424
+
classMA_None2:None{
1425
+
@MainActor
1426
+
overridefunc method(){ // expected-error {{main actor-isolated instance method 'method()' has different actor isolation from nonisolated overridden declaration}}
1427
+
beets_ma()
1428
+
}
1429
+
}
1430
+
1431
+
classMADirect{
1432
+
@MainActorfunc method1(){}
1433
+
@MainActorfunc method2(){}
1434
+
}
1435
+
1436
+
classNone_MADirect:MADirect{
1437
+
// default-isolation vs overridden-MainActor = mainactor
1438
+
overridefunc method1(){beets_ma()}
1439
+
1440
+
// directly-nonisolated vs overridden mainactor = nonisolated
1441
+
nonisolatedoverridefunc method2(){beets_ma()} // expected-error {{call to main actor-isolated global function 'beets_ma()' in a synchronous nonisolated context}}
1442
+
}
1443
+
1444
+
@SomeGlobalActor
1445
+
classSGA_MADirect:MADirect{
1446
+
// inferred-SomeGlobalActor vs overridden-MainActor = mainactor
1447
+
overridefunc method1(){beets_ma()}
1448
+
1449
+
// directly-nonisolated vs overridden-MainActor = nonisolated
1450
+
nonisolatedoverridefunc method2(){beets_ma()} // expected-error {{call to main actor-isolated global function 'beets_ma()' in a synchronous nonisolated context}}
0 commit comments