Skip to content

Commit 9df8375

Browse files
committed
[CSBindings] Delay attempting type variable if it's involved in unresolved call
If type variable is still connected to `ApplicableFunction` that means it's either an argument, result or represents a function (member reference, operator) being applied. Regardless of exact location such type variable should be delayed until call is completely resolved to get additional context from parameters, result type of a function being applied.
1 parent 54406b4 commit 9df8375

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,23 +1172,17 @@ bool ConstraintSystem::PotentialBindings::infer(
11721172
case ConstraintKind::ApplicableFunction:
11731173
case ConstraintKind::DynamicCallableApplicableFunction:
11741174
case ConstraintKind::BindOverload: {
1175-
// If this variable is in the left-hand side, it is fully bound.
1176-
SmallPtrSet<TypeVariableType *, 4> typeVars;
1177-
findInferableTypeVars(cs.simplifyType(constraint->getFirstType()),
1178-
typeVars);
1179-
if (typeVars.count(TypeVar))
1180-
DelayedBy.push_back(constraint);
1181-
1182-
if (InvolvesTypeVariables)
1183-
return false;
1184-
1185-
// If this and another type variable occur, this result involves
1186-
// type variables.
1187-
findInferableTypeVars(cs.simplifyType(constraint->getSecondType()),
1188-
typeVars);
1189-
if (typeVars.size() > 1 && typeVars.count(TypeVar))
1190-
InvolvesTypeVariables = true;
1175+
// It's possible that type of member couldn't be determined,
1176+
// and if so it would be beneficial to bind member to a hole
1177+
// early to propagate that information down to arguments,
1178+
// result type of a call that references such a member.
1179+
if (cs.shouldAttemptFixes() && TypeVar->getImpl().canBindToHole()) {
1180+
if (ConstraintSystem::typeVarOccursInType(
1181+
TypeVar, cs.simplifyType(constraint->getSecondType())))
1182+
break;
1183+
}
11911184

1185+
DelayedBy.push_back(constraint);
11921186
break;
11931187
}
11941188

0 commit comments

Comments
 (0)