@@ -962,12 +962,13 @@ bool TypeVarBindingProducer::computeNext() {
962
962
963
963
bool TypeVariableBinding::attempt (ConstraintSystem &cs) const {
964
964
auto type = Binding.BindingType ;
965
- auto *locator = TypeVar->getImpl ().getLocator ();
965
+ auto *srcLocator = Binding.getLocator ();
966
+ auto *dstLocator = TypeVar->getImpl ().getLocator ();
966
967
967
968
if (Binding.hasDefaultedLiteralProtocol ()) {
968
- type = cs.openUnboundGenericType (type, locator );
969
+ type = cs.openUnboundGenericType (type, dstLocator );
969
970
type = type->reconstituteSugar (/* recursive=*/ false );
970
- } else if (Binding. getSourceKind () == ConstraintKind::ArgumentConversion &&
971
+ } else if (srcLocator-> isLastElement <LocatorPathElt::ApplyArgToParam>() &&
971
972
!type->hasTypeVariable () && cs.isCollectionType (type)) {
972
973
// If the type binding comes from the argument conversion, let's
973
974
// instead of binding collection types directly, try to bind
@@ -978,25 +979,27 @@ bool TypeVariableBinding::attempt(ConstraintSystem &cs) const {
978
979
auto UGT = UnboundGenericType::get (BGT->getDecl (), BGT->getParent (),
979
980
BGT->getASTContext ());
980
981
981
- type = cs.openUnboundGenericType (UGT, locator );
982
+ type = cs.openUnboundGenericType (UGT, dstLocator );
982
983
type = type->reconstituteSugar (/* recursive=*/ false );
983
984
}
984
985
985
- cs.addConstraint (ConstraintKind::Bind, TypeVar, type, Binding. getLocator () );
986
+ cs.addConstraint (ConstraintKind::Bind, TypeVar, type, srcLocator );
986
987
987
988
// If this was from a defaultable binding note that.
988
989
if (Binding.isDefaultableBinding ()) {
989
- cs.DefaultedConstraints .push_back (Binding.getLocator ());
990
-
991
- if (locator->isForGenericParameter () && type->isHole ()) {
992
- // Drop `generic parameter` locator element so that all missing
993
- // generic parameters related to the same path can be coalesced later.
994
- auto path = locator->getPath ();
995
- auto genericParam = locator->getGenericParameter ();
996
- auto *fix = DefaultGenericArgument::create (cs, genericParam,
997
- cs.getConstraintLocator (locator->getAnchor (), path.drop_back ()));
998
- if (cs.recordFix (fix))
999
- return true ;
990
+ cs.DefaultedConstraints .push_back (srcLocator);
991
+
992
+ if (type->isHole ()) {
993
+ if (auto *GP = TypeVar->getImpl ().getGenericParameter ()) {
994
+ auto path = dstLocator->getPath ();
995
+ // Drop `generic parameter` locator element so that all missing
996
+ // generic parameters related to the same path can be coalesced later.
997
+ auto *fix = DefaultGenericArgument::create (
998
+ cs, GP,
999
+ cs.getConstraintLocator (dstLocator->getAnchor (), path.drop_back ()));
1000
+ if (cs.recordFix (fix))
1001
+ return true ;
1002
+ }
1000
1003
}
1001
1004
}
1002
1005
0 commit comments