Skip to content

Commit e45b379

Browse files
committed
[CodeCompletion] Don’t pass LeaveClosureBodiesUnchecked for solver-based code completion
1 parent 868990d commit e45b379

File tree

5 files changed

+20
-9
lines changed

5 files changed

+20
-9
lines changed

lib/Sema/TypeCheckCodeCompletion.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,9 @@ getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
307307

308308
ConstraintSystemOptions options;
309309
options |= ConstraintSystemFlags::SuppressDiagnostics;
310-
options |= ConstraintSystemFlags::LeaveClosureBodyUnchecked;
310+
if (!Context.CompletionCallback) {
311+
options |= ConstraintSystemFlags::LeaveClosureBodyUnchecked;
312+
}
311313

312314
// Construct a constraint system from this expression.
313315
ConstraintSystem cs(dc, options);
@@ -400,7 +402,6 @@ getTypeOfCompletionOperatorImpl(DeclContext *DC, Expr *expr,
400402

401403
ConstraintSystemOptions options;
402404
options |= ConstraintSystemFlags::SuppressDiagnostics;
403-
options |= ConstraintSystemFlags::LeaveClosureBodyUnchecked;
404405

405406
// Construct a constraint system from this expression.
406407
ConstraintSystem CS(DC, options);
@@ -612,8 +613,9 @@ bool TypeChecker::typeCheckForCodeCompletion(
612613
options |= ConstraintSystemFlags::AllowFixes;
613614
options |= ConstraintSystemFlags::SuppressDiagnostics;
614615
options |= ConstraintSystemFlags::ForCodeCompletion;
615-
options |= ConstraintSystemFlags::LeaveClosureBodyUnchecked;
616-
616+
if (!Context.CompletionCallback) {
617+
options |= ConstraintSystemFlags::LeaveClosureBodyUnchecked;
618+
}
617619

618620
ConstraintSystem cs(DC, options);
619621

lib/Sema/TypeCheckStmt.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2388,8 +2388,9 @@ bool TypeCheckASTNodeAtLocRequest::evaluate(
23882388
}
23892389
}
23902390

2391-
TypeChecker::typeCheckASTNode(finder.getRef(), DC,
2392-
/*LeaveBodyUnchecked=*/true);
2391+
bool LeaveBodyUnchecked = !ctx.CompletionCallback;
2392+
2393+
TypeChecker::typeCheckASTNode(finder.getRef(), DC, LeaveBodyUnchecked);
23932394
return false;
23942395
}
23952396

test/IDE/complete_in_closures.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ struct NestedStructWithClosureMember1 {
104104
struct StructWithClosureMemberAndLocal {
105105
var c = {
106106
var x = 0
107-
#^DELAYED_10?check=WITH_GLOBAL_DECLS_AND_LOCAL1;xfail=https://github.com/apple/swift/issues/58273^#
107+
#^DELAYED_10?check=WITH_GLOBAL_DECLS_AND_LOCAL1^#
108108
}
109109
}
110110

test/IDE/complete_skipbody.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ func test(valueOptOpt: MyStruct??) {
4545
case let x where x < 2:
4646
let unrelated3 = FORBIDDEN_Struct()
4747
_ = { xx in
48-
let unrelated4 = FORBIDDEN_Struct()
49-
5048
if xx == localFunc(value.#^FUNCTIONBODY^#) {
5149
let unrelated5 = FORBIDDEN_Struct()
5250
return 1

test/IDE/complete_with_trailing_closure.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,20 @@ func sink(receiveValue: (MyArray) -> Void) {
1616
func foo() {
1717
sink { items in
1818
let a = items.#^COMPLETE_WITHOUT_SPACE?check=CHECK^#map{ $0.content }
19+
}
20+
sink { items in
1921
let b = items.#^COMPLETE_WITH_SPACE?check=CHECK^# map{ $0.content }
22+
}
23+
sink { items in
2024
let c = items.#^COMPLETE_WITH_SPACE_AND_PARENS?check=CHECK^# map({ $0.content })
25+
}
26+
sink { items in
2127
let d = items.#^COMPLETE_WITHOUT_SPACE_BUT_PARENS?check=CHECK^#map({ $0.content })
28+
}
29+
sink { items in
2230
let e = items.#^COMPLETE_WITHOUT_MAP?check=CHECK^# { $0.content }
31+
}
32+
sink { items in
2333
let f = items.#^COMPLETE_WITHOUT_MAP_BUT_PARENS?check=CHECK^# ({ $0.content })
2434
}
2535
}

0 commit comments

Comments
 (0)