Skip to content

Commit 4ace882

Browse files
committed
[ConstraintSystem] Introduce a fallback type for key path literals
This is a very first step in attempt to move some of the logic from `simplifyKeyPathConstraint` to the inference. This type is going to be used as an anchor to trigger capability inference.
1 parent 59b7593 commit 4ace882

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,6 +2097,10 @@ bool TypeVarBindingProducer::computeNext() {
20972097
}
20982098

20992099
if (newBindings.empty()) {
2100+
// If key path type had contextual types, let's not attempt fallback.
2101+
if (TypeVar->getImpl().isKeyPathType() && !ExploredTypes.empty())
2102+
return false;
2103+
21002104
// Add defaultable constraints (if any).
21012105
for (auto *constraint : DelayedDefaults) {
21022106
if (constraint->getKind() == ConstraintKind::FallbackType) {

lib/Sema/CSGen.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3884,6 +3884,13 @@ namespace {
38843884

38853885
CS.addKeyPathConstraint(kpTy, root, value, componentTypeVars, locator);
38863886

3887+
// Add a fallback constraint so we have an anchor to use for
3888+
// capability inference when there is no context.
3889+
CS.addUnsolvedConstraint(Constraint::create(
3890+
CS, ConstraintKind::FallbackType, kpTy,
3891+
BoundGenericType::get(kpDecl, /*parent=*/Type(), {root, value}),
3892+
CS.getConstraintLocator(E, ConstraintLocator::FallbackType)));
3893+
38873894
return kpTy;
38883895
}
38893896

0 commit comments

Comments
 (0)