@@ -2657,8 +2657,20 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
2657
2657
case ConstraintKind::Subtype:
2658
2658
case ConstraintKind::Conversion:
2659
2659
case ConstraintKind::ArgumentConversion:
2660
- case ConstraintKind::OperatorArgumentConversion:
2660
+ case ConstraintKind::OperatorArgumentConversion: {
2661
+ if (typeVar1) {
2662
+ if (auto *locator = typeVar1->getImpl ().getLocator ()) {
2663
+ // TODO(diagnostics): Only binding here for function types, because
2664
+ // doing so for KeyPath types leaves the constraint system in an
2665
+ // unexpected state for key path diagnostics should we fail.
2666
+ if (locator->isLastElement (ConstraintLocator::KeyPathType) &&
2667
+ type2->is <AnyFunctionType>())
2668
+ return matchTypesBindTypeVar (typeVar1, type2, kind, flags, locator,
2669
+ formUnsolvedResult);
2670
+ }
2671
+ }
2661
2672
return formUnsolvedResult ();
2673
+ }
2662
2674
2663
2675
case ConstraintKind::OpaqueUnderlyingType:
2664
2676
case ConstraintKind::ApplicableFunction:
@@ -5590,22 +5602,6 @@ ConstraintSystem::simplifyKeyPathConstraint(Type keyPathTy,
5590
5602
return SolutionKind::Error;
5591
5603
}
5592
5604
5593
- // If we have nothing else, and there's another constraint on our keyPathTy
5594
- // type variable that's some sort of conversion to a function type, use that
5595
- // constraint's second type.
5596
- if (keyPathTy->isTypeVariableOrMember ()) {
5597
- for (auto constraint : getActiveConstraints ()) {
5598
- if (constraint.getKind () > ConstraintKind::OperatorArgumentConversion)
5599
- continue ;
5600
- if (constraint.getFirstType ().getPointer () == keyPathTy.getPointer ()) {
5601
- auto otherType = constraint.getSecondType ();
5602
- if (otherType->is <FunctionType>() &&
5603
- !tryMatchRootAndValueFromType (otherType))
5604
- return SolutionKind::Error;
5605
- }
5606
- }
5607
- }
5608
-
5609
5605
// See if we resolved overloads for all the components involved.
5610
5606
enum {
5611
5607
ReadOnly,
@@ -5736,10 +5732,7 @@ ConstraintSystem::simplifyKeyPathConstraint(Type keyPathTy,
5736
5732
5737
5733
auto loc = locator.getBaseLocator ();
5738
5734
if (definitelyFunctionType) {
5739
- Type fnType =
5740
- FunctionType::get ({AnyFunctionType::Param (rootTy)}, valueTy,
5741
- AnyFunctionType::ExtInfo ().withThrows (false ));
5742
- return matchTypes (keyPathTy, fnType, ConstraintKind::Bind, subflags, loc);
5735
+ return SolutionKind::Solved;
5743
5736
} else if (!anyComponentsUnresolved ||
5744
5737
(definitelyKeyPathType && capability == ReadOnly)) {
5745
5738
auto resolvedKPTy =
0 commit comments