Skip to content

Commit 88cf178

Browse files
authored
Merge pull request #37888 from DougGregor/actor-isolation-defer
2 parents 7277baa + caf843f commit 88cf178

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
@@ -1407,6 +1407,12 @@ namespace {
14071407
}
14081408
}
14091409

1410+
// "Defer" blocks are treated as if they are in their enclosing context.
1411+
if (auto func = dyn_cast<FuncDecl>(dc)) {
1412+
if (func->isDeferBody())
1413+
continue;
1414+
}
1415+
14101416
// Check isolation of the context itself. We do this separately
14111417
// from the closure check because closures capture specific variables
14121418
// 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)