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
[Concurrency] Don't allow subclasses of nonisolated classes to add global
actor isolation.
Adding global actor isolation via subclassing admits data races because
actor-isolated types are Sendable while nonisolated classes are not (unless
otherwise annotated), so this allowed bypassing Sendable checking.
Copy file name to clipboardExpand all lines: test/ClangImporter/objc_async.swift
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -298,6 +298,7 @@ class BarFrame: PictureFrame {
298
298
@available(SwiftStdlib 5.5,*)
299
299
@SomeGlobalActor
300
300
classBazFrame:NotIsolatedPictureFrame{
301
+
// expected-warning@-1 {{global actor 'SomeGlobalActor'-isolated class 'BazFrame' has different actor isolation from nonisolated superclass 'NotIsolatedPictureFrame'; this is an error in Swift 6}}
Copy file name to clipboardExpand all lines: test/Concurrency/actor_isolation.swift
+6-1Lines changed: 6 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1263,7 +1263,8 @@ actor Counter {
1263
1263
classC2{}
1264
1264
1265
1265
@SomeGlobalActor
1266
-
classC3:C2{} // it's okay to add a global actor to a nonisolated class.
1266
+
classC3:C2{}
1267
+
// expected-warning@-1 {{global actor 'SomeGlobalActor'-isolated class 'C3' has different actor isolation from nonisolated superclass 'C2'; this is an error in Swift 6}}
1267
1268
1268
1269
@GenericGlobalActor<U>
1269
1270
classGenericSuper<U>{}
@@ -1443,6 +1444,8 @@ class None {
1443
1444
// try to add inferred isolation while overriding
1444
1445
@MainActor
1445
1446
classMA_None1:None{
1447
+
// expected-warning@-1 {{main actor-isolated class 'MA_None1' has different actor isolation from nonisolated superclass 'None'; this is an error in Swift 6}}
1448
+
1446
1449
// FIXME: bad note, since the problem is a mismatch in overridden vs inferred isolation; this wont help.
1447
1450
// expected-note@+1 {{add '@MainActor' to make instance method 'method()' part of global actor 'MainActor'}}
1448
1451
overridefunc method(){
@@ -1472,6 +1475,8 @@ class None_MADirect: MADirect {
1472
1475
1473
1476
@SomeGlobalActor
1474
1477
classSGA_MADirect:MADirect{
1478
+
// expected-warning@-1 {{global actor 'SomeGlobalActor'-isolated class 'SGA_MADirect' has different actor isolation from nonisolated superclass 'MADirect'; this is an error in Swift 6}}
1479
+
1475
1480
// inferred-SomeGlobalActor vs overridden-MainActor = mainactor
// expected-warning@-1 {{global actor 'GenericGlobalActor<String>'-isolated class 'SubclassWithGlobalActors' has different actor isolation from nonisolated superclass 'SuperclassWithGlobalActors'; this is an error in Swift 6}}
252
+
251
253
overridefunc f(){} // okay: inferred to @GenericGlobalActor<Int>
252
254
253
255
@GenericGlobalActor<String>overridefunc g(){} // expected-error{{global actor 'GenericGlobalActor<String>'-isolated instance method 'g()' has different actor isolation from global actor 'GenericGlobalActor<Int>'-isolated overridden declaration}}
0 commit comments