Skip to content

Commit caf843f

Browse files
committed
"Defer" blocks are as isolated as their enclosing contexts.
Fixes a regression I introduced recently, rdar://79200626.
1 parent 474aa2e commit caf843f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,12 @@ namespace {
14061406
}
14071407
}
14081408

1409+
// "Defer" blocks are treated as if they are in their enclosing context.
1410+
if (auto func = dyn_cast<FuncDecl>(dc)) {
1411+
if (func->isDeferBody())
1412+
continue;
1413+
}
1414+
14091415
// Check isolation of the context itself. We do this separately
14101416
// from the closure check because closures capture specific variables
14111417
// while general isolation is declaration-based.

test/Concurrency/actor_isolation.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,3 +834,16 @@ func test_invalid_reference_to_actor_member_without_a_call_note() {
834834
}
835835
}
836836
}
837+
838+
// Actor isolation and "defer"
839+
actor Counter {
840+
var counter: Int = 0
841+
842+
func next() -> Int {
843+
defer {
844+
counter = counter + 1
845+
}
846+
847+
return counter
848+
}
849+
}

0 commit comments

Comments
 (0)