Skip to content

Commit

Permalink
Merge pull request apple#37888 from DougGregor/actor-isolation-defer
Browse files Browse the repository at this point in the history
  • Loading branch information
swift-ci committed Jun 11, 2021
2 parents 7277baa + caf843f commit 88cf178
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/Sema/TypeCheckConcurrency.cpp
Expand Up @@ -1407,6 +1407,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
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
}
}

0 comments on commit 88cf178

Please sign in to comment.