@@ -713,22 +713,28 @@ bool ConstraintSystem::tryTypeVariableBindings(
713
713
newBindings.push_back ({subtype, binding.Kind , binding.BindingSource });
714
714
}
715
715
716
- // If we were unsuccessful solving for T?, try solving for T.
717
- if (auto objTy = type->getOptionalObjectType ()) {
718
- if (exploredTypes.insert (objTy->getCanonicalType ()).second ) {
719
- // If T is a type variable, only attempt this if both the
720
- // type variable we are trying bindings for, and the type
721
- // variable we will attempt to bind, both have the same
722
- // polarity with respect to being able to bind lvalues.
723
- if (auto otherTypeVar = objTy->getAs <TypeVariableType>()) {
724
- if (typeVar->getImpl ().canBindToLValue () ==
725
- otherTypeVar->getImpl ().canBindToLValue ()) {
716
+ // Allow solving for T even for a binding kind where that's invalid
717
+ // if fixes are allowed, because that gives us the opportunity to
718
+ // match T? values to the T binding by adding an unwrap fix.
719
+ if (binding.Kind == AllowedBindingKind::Subtypes ||
720
+ shouldAttemptFixes ()) {
721
+ // If we were unsuccessful solving for T?, try solving for T.
722
+ if (auto objTy = type->getOptionalObjectType ()) {
723
+ if (exploredTypes.insert (objTy->getCanonicalType ()).second ) {
724
+ // If T is a type variable, only attempt this if both the
725
+ // type variable we are trying bindings for, and the type
726
+ // variable we will attempt to bind, both have the same
727
+ // polarity with respect to being able to bind lvalues.
728
+ if (auto otherTypeVar = objTy->getAs <TypeVariableType>()) {
729
+ if (typeVar->getImpl ().canBindToLValue () ==
730
+ otherTypeVar->getImpl ().canBindToLValue ()) {
731
+ newBindings.push_back (
732
+ {objTy, binding.Kind , binding.BindingSource });
733
+ }
734
+ } else {
726
735
newBindings.push_back (
727
736
{objTy, binding.Kind , binding.BindingSource });
728
737
}
729
- } else {
730
- newBindings.push_back (
731
- {objTy, binding.Kind , binding.BindingSource });
732
738
}
733
739
}
734
740
}
0 commit comments