Skip to content

Commit ff89c71

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 4f15b47 commit ff89c71

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
@@ -2610,6 +2610,13 @@ namespace {
26102610
return MacroWalking::Expansion;
26112611
}
26122612

2613+
PreWalkResult<Pattern *> walkToPatternPre(Pattern *pattern) override {
2614+
// Walking into patterns leads to nothing good because then we
2615+
// end up visiting the AccessorDecls of a top-level
2616+
// PatternBindingDecl twice.
2617+
return Action::SkipNode(pattern);
2618+
}
2619+
26132620
PreWalkAction walkToDeclPre(Decl *decl) override {
26142621
// Don't walk into local types because nothing in them can
26152622
// 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)