Skip to content

"Defer" blocks are as isolated as their enclosing contexts. #37888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,12 @@ namespace {
}
}

// "Defer" blocks are treated as if they are in their enclosing context.
if (auto func = dyn_cast<FuncDecl>(dc)) {
if (func->isDeferBody())
continue;
}

// Check isolation of the context itself. We do this separately
// from the closure check because closures capture specific variables
// while general isolation is declaration-based.
Expand Down
13 changes: 13 additions & 0 deletions test/Concurrency/actor_isolation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -834,3 +834,16 @@ func test_invalid_reference_to_actor_member_without_a_call_note() {
}
}
}

// Actor isolation and "defer"
actor Counter {
var counter: Int = 0

func next() -> Int {
defer {
counter = counter + 1
}

return counter
}
}