Skip to content

Commit e6a375a

Browse files
authored
Merge pull request #36001 from etcwilde/ewilde/tippy-tapping-that-isolation-checker
[Concurrency] Check actor isolation in TapExprs
2 parents 11dec42 + f2f3e3d commit e6a375a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ namespace {
10721072

10731073
bool shouldWalkCaptureInitializerExpressions() override { return true; }
10741074

1075-
bool shouldWalkIntoTapExpression() override { return false; }
1075+
bool shouldWalkIntoTapExpression() override { return true; }
10761076

10771077
bool walkToDeclPre(Decl *decl) override {
10781078
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {

test/Concurrency/actor_isolation.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,14 @@ extension GenericStruct where T == String {
295295
}
296296
}
297297

298+
@SomeGlobalActor
299+
var number: Int = 42 // expected-note 2 {{mutable state is only available within the actor instance}}
300+
301+
//expected-note@+1{{add '@SomeGlobalActor' to make global function 'badNumberUser()' part of global actor 'SomeGlobalActor'}}
302+
func badNumberUser() {
303+
//expected-error@+1{{var 'number' isolated to global actor 'SomeGlobalActor' can not be referenced from this context}}
304+
print("The protected number is: \(number)")
305+
}
298306

299307
// ----------------------------------------------------------------------
300308
// Non-actor code isolation restrictions
@@ -336,6 +344,9 @@ func testGlobalRestrictions(actor: MyActor) async {
336344
acceptConcurrentClosure { [i] in
337345
_ = i
338346
}
347+
348+
//expected-error@+1{{var 'number' isolated to global actor 'SomeGlobalActor' can not be referenced from this context}}
349+
print("\(number)")
339350
}
340351

341352
func f() {

0 commit comments

Comments
 (0)