File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -818,7 +818,20 @@ class SyntacticElementConstraintGenerator
818
818
819
819
if (patternBinding->isInitializerChecked (index))
820
820
return ;
821
-
821
+
822
+ // Capture list bindings in multi-statement closures get solved as part of
823
+ // the closure's conjunction, which has the DeclContext set to the closure.
824
+ // This is wrong for captures though, which are semantically bound outside
825
+ // of the closure body. So we need to re-adjust their DeclContext here for
826
+ // constraint generation. The constraint system's DeclContext will be wrong
827
+ // for solving, but CSGen should ensure that constraints carry the correct
828
+ // DeclContext.
829
+ std::optional<llvm::SaveAndRestore<DeclContext *>> DCScope;
830
+ if (auto *var = patternBinding->getSingleVar ()) {
831
+ if (var->getParentCaptureList ())
832
+ DCScope.emplace (cs.DC , var->getDeclContext ());
833
+ }
834
+
822
835
auto contextualPattern =
823
836
ContextualPattern::forPatternBindingDecl (patternBinding, index);
824
837
Type patternType = TypeChecker::typeCheckPattern (contextualPattern);
Original file line number Diff line number Diff line change
1
+ // RUN: %target-typecheck-verify-swift
2
+
3
+ // https://github.com/swiftlang/swift/issues/79444
4
+ class C {
5
+ func foo( ) {
6
+ _ = { [ x = " \( self ) " ] in } // expected-warning {{capture 'x' was never used}}
7
+ _ = { [ x = " \( self ) " ] in x }
8
+ _ = { [ x = " \( self ) " ] in
9
+ let y = x
10
+ return y
11
+ }
12
+ _ = { [ x = " \( self ) " ] in
13
+ let fn = { [ y = " \( x) " ] in
14
+ let z = y
15
+ return z
16
+ }
17
+ return fn ( )
18
+ }
19
+ }
20
+ }
You can’t perform that action at this time.
0 commit comments