Skip to content

Commit 2d951ef

Browse files
committed
[CS] Don't bail out of CollectVarRefs early
Upon encountering an ErrorExpr, we were previously bailing from the walk. However, for multi-statement closures, that could result in us missing some variable references required to connect to the closure to its enclosing context. Make sure to continue walking to catch those cases. SR-14709 rdar://78781677
1 parent 382809a commit 2d951ef

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

lib/Sema/CSGen.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2519,10 +2519,8 @@ namespace {
25192519
std::pair<bool, Expr *> walkToExprPre(Expr *expr) override {
25202520
// If there are any error expressions in this closure
25212521
// it wouldn't be possible to infer its type.
2522-
if (isa<ErrorExpr>(expr)) {
2522+
if (isa<ErrorExpr>(expr))
25232523
hasErrorExprs = true;
2524-
return {false, nullptr};
2525-
}
25262524

25272525
// Retrieve type variables from references to var decls.
25282526
if (auto *declRef = dyn_cast<DeclRefExpr>(expr)) {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// RUN: %swift-ide-test --code-completion --source-filename %s --code-completion-token=CC
2+
3+
struct Listing {}
4+
5+
protocol View2 {}
6+
7+
extension View2 {
8+
@available(macOS 10.15, *)
9+
func onTapGesturf(perform action: () -> Void) -> some View2 { fatalError() }
10+
}
11+
12+
@resultBuilder struct ViewBuilder2 {
13+
static func buildBlock() -> Never { fatalError() }
14+
static func buildBlock<Content>(_ content: Content) -> Content where Content : View2 { fatalError() }
15+
}
16+
17+
struct HStack2<Content> : View2 {
18+
init(@ViewBuilder2 content: () -> Content) { fatalError() }
19+
}
20+
21+
struct ItemImage2 : View2 {
22+
init(path: String) {}
23+
}
24+
25+
struct ForEach2<Data, Content>: View2 {
26+
init(_ data: [Listing], @ViewBuilder2 content: (Data) -> Content) {}
27+
}
28+
29+
30+
struct TodayNookazonSection {
31+
32+
let listings: [Listing]
33+
34+
@available(macOS 10.15, *)
35+
@ViewBuilder2 var body: some View2 {
36+
ForEach2(listings) { listing in
37+
HStack2 {
38+
HStack2 {
39+
ItemImage2(path#^CC^#: "abc")
40+
}
41+
.onTapGesturf {
42+
listing
43+
}
44+
}
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)