Skip to content

Commit 48e71f7

Browse files
authored
Merge pull request #15559 from xedin/rdar-38144674
[Sema] Fix `PreCheckExpression` to avoid walking into capture lists
2 parents d6c6e3e + e8cd3f9 commit 48e71f7

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,12 @@ namespace {
824824
TC.typeCheckDecl(capture.Var, true);
825825
TC.typeCheckDecl(capture.Var, false);
826826
}
827-
return finish(true, expr);
827+
828+
// Since closure expression is contained by capture list
829+
// let's handle it directly to avoid walking into capture
830+
// list itself.
831+
captureList->getClosureBody()->walk(*this);
832+
return finish(false, expr);
828833
}
829834

830835
// For closures, type-check the patterns and result type as written,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %target-typecheck-verify-swift %s
2+
3+
func foo(optional: Int?) {
4+
_ = { [value = optional ?? 0]
5+
in
6+
_ = value
7+
}
8+
9+
_ = [1].map { [number = optional ?? 1] value -> String in
10+
return number.description
11+
}
12+
}

0 commit comments

Comments
 (0)