Skip to content

Commit 1b5ce2b

Browse files
committed
[CSBindings] Start recording SpecifyContextualTypeForNil fix when nil is bound to a hole
1 parent 7d6a110 commit 1b5ce2b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,15 @@ void ConstraintSystem::PotentialBindings::finalize(
368368
PotentiallyIncomplete = true;
369369
}
370370

371+
// Delay resolution of the `nil` literal to a hole until
372+
// the very end to give it a change to be bound to some
373+
// other type, just like code completion expression which
374+
// relies solely on contextual information.
375+
if (locator->directlyAt<NilLiteralExpr>()) {
376+
FullyBound = true;
377+
PotentiallyIncomplete = true;
378+
}
379+
371380
addPotentialBinding(PotentialBinding::forHole(TypeVar, locator));
372381
}
373382

@@ -1268,6 +1277,8 @@ bool TypeVariableBinding::attempt(ConstraintSystem &cs) const {
12681277
return true;
12691278

12701279
fix = SpecifyKeyPathRootType::create(cs, dstLocator);
1280+
} else if (dstLocator->directlyAt<NilLiteralExpr>()) {
1281+
fix = SpecifyContextualTypeForNil::create(cs, dstLocator);
12711282
}
12721283

12731284
if (fix && cs.recordFix(fix))

0 commit comments

Comments
 (0)