Skip to content

Commit ed43dec

Browse files
committed
Concurrency: Skip Patterns when checking isolation
Due to a quirk of the ASTVisitor, we would then visit accessors twice, the first time as part of the PatternBindingDecl inside the TopLevelCodeDecl, and at that point the accessor body has not yet been type checked.
1 parent 3b29aad commit ed43dec

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,6 +2624,13 @@ namespace {
26242624
return MacroWalking::Expansion;
26252625
}
26262626

2627+
PreWalkResult<Pattern *> walkToPatternPre(Pattern *pattern) override {
2628+
// Walking into patterns leads to nothing good because then we
2629+
// end up visiting the AccessorDecls of a top-level
2630+
// PatternBindingDecl twice.
2631+
return Action::SkipNode(pattern);
2632+
}
2633+
26272634
PreWalkAction walkToDeclPre(Decl *decl) override {
26282635
// Don't walk into local types because nothing in them can
26292636
// change the outcome of our analysis, and we don't want to
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %target-typecheck-verify-swift -swift-version 6
2+
3+
class NonSendable {} // expected-note 2{{class 'NonSendable' does not conform to the 'Sendable' protocol}}
4+
5+
var testLocalCaptures: Int {
6+
let ns = NonSendable()
7+
8+
@Sendable func localFunc() -> NonSendable {
9+
return ns // expected-error {{capture of 'ns' with non-sendable type 'NonSendable' in a `@Sendable` local function}}
10+
}
11+
12+
let _: @Sendable () -> NonSendable = {
13+
return ns // expected-error {{capture of 'ns' with non-sendable type 'NonSendable' in a `@Sendable` closure}}
14+
}
15+
16+
return 3
17+
}

0 commit comments

Comments
 (0)