Skip to content

Commit af73ca3

Browse files
authored
Merge pull request #83704 from hamishknight/fix-stress-tester-regression
[CS] Record `SkipUnhandledConstructInResultBuilder` for completion
2 parents 68cf0b9 + eb7aa62 commit af73ca3

File tree

2 files changed

+109
-7
lines changed

2 files changed

+109
-7
lines changed

lib/Sema/BuilderTransform.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,13 +1153,6 @@ ConstraintSystem::matchResultBuilder(AnyFunctionRef fn, Type builderType,
11531153
if (auto unsupported = transform.getUnsupportedElement()) {
11541154
assert(!body);
11551155

1156-
// If we're solving for code completion and the body contains the code
1157-
// completion location, fall back to solving as a regular function body.
1158-
if (isForCodeCompletion() &&
1159-
containsIDEInspectionTarget(fn.getBody())) {
1160-
return std::nullopt;
1161-
}
1162-
11631156
// If we aren't supposed to attempt fixes, fail.
11641157
if (!shouldAttemptFixes()) {
11651158
return getTypeMatchFailure(locator);
@@ -1173,6 +1166,13 @@ ConstraintSystem::matchResultBuilder(AnyFunctionRef fn, Type builderType,
11731166
return getTypeMatchFailure(locator);
11741167
}
11751168

1169+
// If we're solving for code completion and the body contains the code
1170+
// completion location, fall back to solving as a regular function body.
1171+
if (isForCodeCompletion() &&
1172+
containsIDEInspectionTarget(fn.getBody())) {
1173+
return std::nullopt;
1174+
}
1175+
11761176
if (auto *closure =
11771177
getAsExpr<ClosureExpr>(fn.getAbstractClosureExpr())) {
11781178
recordTypeVariablesAsHoles(getClosureType(closure));

test/IDE/pr-83704.swift

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// RUN: %batch-code-completion
2+
3+
@resultBuilder
4+
struct Builder0 {
5+
static func buildBlock<T>(_ x: T) -> T { x }
6+
static func buildArray<T>(_ components: [T]) -> T { components.first! }
7+
}
8+
@resultBuilder
9+
struct Builder1 {
10+
static func buildBlock<T>(_ x: T) -> T { x }
11+
}
12+
@resultBuilder
13+
struct Builder2 {
14+
static func buildBlock<T>(_ x: T) -> T { x }
15+
}
16+
@resultBuilder
17+
struct Builder3 {
18+
static func buildBlock<T>(_ x: T) -> T { x }
19+
}
20+
@resultBuilder
21+
struct Builder4 {
22+
static func buildBlock<T>(_ x: T) -> T { x }
23+
}
24+
@resultBuilder
25+
struct Builder5 {
26+
static func buildBlock<T>(_ x: T) -> T { x }
27+
}
28+
@resultBuilder
29+
struct Builder6 {
30+
static func buildBlock<T>(_ x: T) -> T { x }
31+
}
32+
@resultBuilder
33+
struct Builder7 {
34+
static func buildBlock<T>(_ x: T) -> T { x }
35+
}
36+
@resultBuilder
37+
struct Builder8 {
38+
static func buildBlock<T>(_ x: T) -> T { x }
39+
}
40+
@resultBuilder
41+
struct Builder9 {
42+
static func buildBlock<T>(_ x: T) -> T { x }
43+
}
44+
45+
protocol P0 {}
46+
protocol P1 {}
47+
protocol P2 {}
48+
protocol P3 {}
49+
protocol P4 {}
50+
protocol P5 {}
51+
protocol P6 {}
52+
protocol P7 {}
53+
protocol P8 {}
54+
protocol P9 {}
55+
56+
struct S<T> {}
57+
extension S: P0 where T : P0 { init<U>(@Builder0 fn: () -> U) {} }
58+
extension S: P1 where T : P1 { init<U>(@Builder1 fn: () -> U) {} }
59+
extension S: P2 where T : P2 { init<U>(@Builder2 fn: () -> U) {} }
60+
extension S: P3 where T : P3 { init<U>(@Builder3 fn: () -> U) {} }
61+
extension S: P4 where T : P4 { init<U>(@Builder4 fn: () -> U) {} }
62+
extension S: P5 where T : P5 { init<U>(@Builder5 fn: () -> U) {} }
63+
extension S: P6 where T : P6 { init<U>(@Builder6 fn: () -> U) {} }
64+
extension S: P7 where T : P7 { init<U>(@Builder7 fn: () -> U) {} }
65+
extension S: P8 where T : P8 { init<U>(@Builder8 fn: () -> U) {} }
66+
extension S: P9 where T : P9 { init<U>(@Builder9 fn: () -> U) {} }
67+
68+
struct K {
69+
var foo: Int
70+
}
71+
72+
// Make sure we ignore all the result builders that cannot handle for loops
73+
// and just use Builder0. There's also no way 'T' can be inferred here but
74+
// that doesn't really matter for this test.
75+
func foo(_ ks: [K]) {
76+
S {
77+
for k0 in ks {
78+
S {
79+
for k1 in ks {
80+
S {
81+
for k2 in ks {
82+
S {
83+
for k3 in ks {
84+
S {
85+
for k4 in ks {
86+
S {
87+
for k5 in ks {
88+
k5.#^COMPLETE^#
89+
// COMPLETE: Decl[InstanceVar]/CurrNominal: foo[#Int#]; name=foo
90+
}
91+
}
92+
}
93+
}
94+
}
95+
}
96+
}
97+
}
98+
}
99+
}
100+
}
101+
}
102+
}

0 commit comments

Comments
 (0)