Skip to content

Commit 20f8a37

Browse files
committed
[ConstraintSystem] Allow code completion type to be a hole
Code completion expression type could be a hole if and only if there is obosolutely no contextual information available e.g. `let _ = .#^MEMBER^#`
1 parent 627a1c0 commit 20f8a37

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,14 @@ void ConstraintSystem::PotentialBindings::finalize(
335335
if (locator->isLastElement<LocatorPathElt::MemberRefBase>())
336336
PotentiallyIncomplete = true;
337337

338+
// Delay resolution of the code completion expression until
339+
// the very end to give it a chance to be bound to some
340+
// contextual type even if it's a hole.
341+
if (locator->directlyAt<CodeCompletionExpr>()) {
342+
FullyBound = true;
343+
PotentiallyIncomplete = true;
344+
}
345+
338346
addPotentialBinding(PotentialBinding::forHole(TypeVar, locator));
339347
}
340348

lib/Sema/CSGen.cpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,23 +1009,9 @@ namespace {
10091009
virtual Type visitCodeCompletionExpr(CodeCompletionExpr *E) {
10101010
CS.Options |= ConstraintSystemFlags::SuppressDiagnostics;
10111011
auto locator = CS.getConstraintLocator(E);
1012-
auto ty = CS.createTypeVariable(locator,
1013-
TVO_CanBindToLValue |
1014-
TVO_CanBindToNoEscape);
1015-
1016-
// Defaults to the type of the base expression if we have a base
1017-
// expression.
1018-
// FIXME: This is just to keep the old behavior where `foo(base.<HERE>)`
1019-
// the argument is type checked to the type of the 'base'. Ideally, code
1020-
// completion expression should be defauled to 'UnresolvedType'
1021-
// regardless of the existence of the base expression. But the constraint
1022-
// system is simply not ready for that.
1023-
if (auto base = E->getBase()) {
1024-
CS.addConstraint(ConstraintKind::Defaultable, ty, CS.getType(base),
1025-
locator);
1026-
}
1027-
1028-
return ty;
1012+
return CS.createTypeVariable(locator, TVO_CanBindToLValue |
1013+
TVO_CanBindToNoEscape |
1014+
TVO_CanBindToHole);
10291015
}
10301016

10311017
Type visitNilLiteralExpr(NilLiteralExpr *expr) {

0 commit comments

Comments
 (0)