Skip to content

Commit 78749d8

Browse files
authored
Merge pull request #63856 from ahoppen/ahoppen/some-leaveclosurebodiesunchecked-changes
[IDE] A few minor changes to set `LeaveClosureBodiesUnchecked` to false in more places
2 parents fe8a277 + 47607f6 commit 78749d8

File tree

5 files changed

+22
-29
lines changed

5 files changed

+22
-29
lines changed

lib/IDE/CursorInfo.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ namespace {
3434
// MARK: - Utilities
3535

3636
void typeCheckDeclAndParentClosures(ValueDecl *VD) {
37+
if (!VD) {
38+
return;
39+
}
3740
// We need to type check any parent closures because their types are
3841
// encoded in the USR of ParentContexts in the cursor info response.
3942
auto DC = VD->getDeclContext();

lib/Sema/TypeCheckCodeCompletion.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -633,23 +633,6 @@ bool TypeChecker::typeCheckForCodeCompletion(
633633
if (solutions.empty())
634634
return CompletionResult::Fallback;
635635

636-
// If code completion expression resides inside of multi-statement
637-
// closure body it could either be type-checked together with the context
638-
// or not, it's impossible to say without checking.
639-
if (contextAnalyzer.locatedInMultiStmtClosure()) {
640-
if (!hasTypeForCompletion(solutions.front(), contextAnalyzer)) {
641-
// At this point we know the code completion node wasn't checked with
642-
// the closure's surrounding context, so can defer to regular
643-
// type-checking for the current call to typeCheckExpression. If that
644-
// succeeds we will get a second call to typeCheckExpression for the
645-
// body of the closure later and can gather completions then. If it
646-
// doesn't we rely on the fallback typechecking in the subclasses of
647-
// TypeCheckCompletionCallback that considers in isolation a
648-
// sub-expression of the closure that contains the completion location.
649-
return CompletionResult::NotApplicable;
650-
}
651-
}
652-
653636
// FIXME: instead of filtering, expose the score and viability to clients.
654637
// Remove solutions that skipped over/ignored the code completion point
655638
// or that require fixes and have a score that is worse than the best.

lib/Sema/TypeCheckStmt.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2171,7 +2171,7 @@ bool TypeCheckASTNodeAtLocRequest::evaluate(
21712171
if (auto Init = PBD->getInit(i)) {
21722172
if (!PBD->isInitializerChecked(i)) {
21732173
typeCheckPatternBinding(PBD, i,
2174-
/*LeaveClosureBodyUnchecked=*/true);
2174+
/*LeaveClosureBodyUnchecked=*/false);
21752175
// Retrieve the accessor's body to trigger RecontextualizeClosures
21762176
// This is important to get the correct USR of variables defined
21772177
// in closures initializing lazy variables.
@@ -2393,8 +2393,6 @@ bool TypeCheckASTNodeAtLocRequest::evaluate(
23932393
}
23942394
}
23952395

2396-
bool LeaveBodyUnchecked = !ctx.CompletionCallback;
2397-
23982396
// The enclosing closure might be a single expression closure or a function
23992397
// builder closure. In such cases, the body elements are type checked with
24002398
// the closure itself. So we need to try type checking the enclosing closure
@@ -2418,17 +2416,13 @@ bool TypeCheckASTNodeAtLocRequest::evaluate(
24182416
auto ActorIsolation = determineClosureActorIsolation(
24192417
CE, __Expr_getType, __AbstractClosureExpr_getActorIsolation);
24202418
CE->setActorIsolation(ActorIsolation);
2421-
if (!LeaveBodyUnchecked) {
2422-
// Type checking the parent closure also type checked this node.
2423-
// Nothing to do anymore.
2424-
return false;
2425-
}
2426-
if (CE->getBodyState() != ClosureExpr::BodyState::ReadyForTypeChecking)
2427-
return false;
2419+
// Type checking the parent closure also type checked this node.
2420+
// Nothing to do anymore.
2421+
return false;
24282422
}
24292423
}
24302424

2431-
TypeChecker::typeCheckASTNode(finder.getRef(), DC, LeaveBodyUnchecked);
2425+
TypeChecker::typeCheckASTNode(finder.getRef(), DC, /*LeaveBodyUnchecked=*/false);
24322426
return false;
24332427
}
24342428

test/IDE/complete_call_arg.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ func curry<T1, T2, R>(_ f: @escaping (T1, T2) -> R) -> (T1) -> (T2) -> R {
469469
// NESTED_CLOSURE: Begin completions
470470
// FIXME: Should be '/TypeRelation[Invalid]: t2[#T2#]'
471471
// NESTED_CLOSURE: Decl[LocalVar]/Local: t2; name=t2
472-
// NESTED_CLOSURE: Decl[LocalVar]/Local: t1[#T1#]; name=t1
472+
// NESTED_CLOSURE: Decl[LocalVar]/Local: t1; name=t1
473473
}
474474

475475
func trailingClosureLocal(x: Int, fn: (Int) -> Void) {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
struct MyStruct {
2+
var identifier: String
3+
}
4+
5+
func takeClosure(_ x: () -> Void) {}
6+
7+
func test() {
8+
takeClosure {
9+
let foo = MyStruct()
10+
// RUN: %sourcekitd-test -req=cursor -pos=%(line + 1):5 %s -- %s
11+
foo.identifier = "\(item.category)#\(item.name)"
12+
}
13+
}

0 commit comments

Comments
 (0)