Skip to content

Commit ecff1fa

Browse files
committed
"Defer" blocks are as isolated as their enclosing contexts.
Fixes a regression I introduced recently, rdar://79200626. (cherry picked from commit caf843f)
1 parent 4575cd3 commit ecff1fa

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
@@ -1549,6 +1549,12 @@ namespace {
15491549
}
15501550
}
15511551

1552+
// "Defer" blocks are treated as if they are in their enclosing context.
1553+
if (auto func = dyn_cast<FuncDecl>(dc)) {
1554+
if (func->isDeferBody())
1555+
continue;
1556+
}
1557+
15521558
// Check isolation of the context itself. We do this separately
15531559
// from the closure check because closures capture specific variables
15541560
// 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
@@ -845,3 +845,16 @@ func test_invalid_reference_to_actor_member_without_a_call_note() {
845845
}
846846
}
847847
}
848+
849+
// Actor isolation and "defer"
850+
actor Counter {
851+
var counter: Int = 0
852+
853+
func next() -> Int {
854+
defer {
855+
counter = counter + 1
856+
}
857+
858+
return counter
859+
}
860+
}

0 commit comments

Comments
 (0)