File tree Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -2025,18 +2025,21 @@ void swift::checkOverrideActorIsolation(ValueDecl *value) {
2025
2025
static bool shouldDiagnoseExistingDataRaces (const DeclContext *dc) {
2026
2026
while (!dc->isModuleScopeContext ()) {
2027
2027
if (auto closure = dyn_cast<AbstractClosureExpr>(dc)) {
2028
- // Async closures use concurrency features.
2029
- if (closure->getType () && closure->isBodyAsync ())
2030
- return true ;
2028
+ // Async and concurrent closures use concurrency features.
2029
+ if (auto closureType = closure->getType ()) {
2030
+ if (auto fnType = closureType->getAs <AnyFunctionType>())
2031
+ if (fnType->isAsync () || fnType->isConcurrent ())
2032
+ return true ;
2033
+ }
2031
2034
} else if (auto decl = dc->getAsDecl ()) {
2032
2035
// If any isolation attributes are present, we're using concurrency
2033
2036
// features.
2034
2037
if (getIsolationFromAttributes (decl, /* shouldDiagnose=*/ false ))
2035
2038
return true ;
2036
2039
2037
2040
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
2038
- // Async functions use concurrency features.
2039
- if (func->hasAsync ())
2041
+ // Async and concurrent functions use concurrency features.
2042
+ if (func->hasAsync () || func-> isConcurrent () )
2040
2043
return true ;
2041
2044
2042
2045
// If there is an explicit @asyncHandler, we're using concurrency
Original file line number Diff line number Diff line change 2
2
// REQUIRES: concurrency
3
3
4
4
let immutableGlobal : String = " hello "
5
- var mutableGlobal : String = " can't touch this " // expected-note 3 {{var declared here}}
5
+ var mutableGlobal : String = " can't touch this " // expected-note 5 {{var declared here}}
6
6
7
7
func globalFunc( ) { }
8
8
func acceptClosure< T> ( _: ( ) -> T ) { }
@@ -334,6 +334,16 @@ func testGlobalRestrictions(actor: MyActor) async {
334
334
print ( i)
335
335
}
336
336
337
+ func f( ) {
338
+ acceptConcurrentClosure {
339
+ _ = mutableGlobal // expected-warning{{reference to var 'mutableGlobal' is not concurrency-safe because it involves shared mutable state}}
340
+ }
341
+
342
+ @concurrent func g( ) {
343
+ _ = mutableGlobal // expected-warning{{reference to var 'mutableGlobal' is not concurrency-safe because it involves shared mutable state}}
344
+ }
345
+ }
346
+
337
347
// ----------------------------------------------------------------------
338
348
// Local function isolation restrictions
339
349
// ----------------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments