@@ -3697,7 +3697,8 @@ static bool diagnoseConflictingGenericArguments(ConstraintSystem &cs,
3697
3697
solution.Fixes , [](const ConstraintFix *fix) -> bool {
3698
3698
return fix->getKind () == FixKind::AllowArgumentTypeMismatch ||
3699
3699
fix->getKind () == FixKind::AllowFunctionTypeMismatch ||
3700
- fix->getKind () == FixKind::AllowTupleTypeMismatch;
3700
+ fix->getKind () == FixKind::AllowTupleTypeMismatch ||
3701
+ fix->getKind () == FixKind::GenericArgumentsMismatch;
3701
3702
});
3702
3703
});
3703
3704
@@ -3711,24 +3712,27 @@ static bool diagnoseConflictingGenericArguments(ConstraintSystem &cs,
3711
3712
genericParams;
3712
3713
// Consider only representative type variables shared across
3713
3714
// all of the solutions.
3714
- for (auto *typeVar : cs.getTypeVariables ()) {
3715
- if (auto *GP = typeVar->getImpl ().getGenericParameter ()) {
3716
- auto *locator = typeVar->getImpl ().getLocator ();
3717
- auto *repr = cs.getRepresentative (typeVar);
3718
- // If representative is another generic parameter let's
3719
- // use its generic parameter type instead of originator's,
3720
- // but it's possible that generic parameter is equated to
3721
- // some other type e.g.
3722
- //
3723
- // func foo<T>(_: T) -> T {}
3724
- //
3725
- // In this case when reference to function `foo` is "opened"
3726
- // type variable representing `T` would be equated to
3727
- // type variable representing a result type of the reference.
3728
- if (auto *reprGP = repr->getImpl ().getGenericParameter ())
3729
- GP = reprGP;
3715
+ for (auto &solution : solutions) {
3716
+ for (auto &typeBinding : solution.typeBindings ) {
3717
+ auto *typeVar = typeBinding.first ;
3718
+ if (auto *GP = typeVar->getImpl ().getGenericParameter ()) {
3719
+ auto *locator = typeVar->getImpl ().getLocator ();
3720
+ auto *repr = cs.getRepresentative (typeVar);
3721
+ // If representative is another generic parameter let's
3722
+ // use its generic parameter type instead of originator's,
3723
+ // but it's possible that generic parameter is equated to
3724
+ // some other type e.g.
3725
+ //
3726
+ // func foo<T>(_: T) -> T {}
3727
+ //
3728
+ // In this case when reference to function `foo` is "opened"
3729
+ // type variable representing `T` would be equated to
3730
+ // type variable representing a result type of the reference.
3731
+ if (auto *reprGP = repr->getImpl ().getGenericParameter ())
3732
+ GP = reprGP;
3730
3733
3731
- genericParams[repr] = {GP, getLoc (locator->getAnchor ())};
3734
+ genericParams[repr] = {GP, getLoc (locator->getAnchor ())};
3735
+ }
3732
3736
}
3733
3737
}
3734
3738
@@ -3743,6 +3747,14 @@ static bool diagnoseConflictingGenericArguments(ConstraintSystem &cs,
3743
3747
llvm::SmallSetVector<Type, 4 > arguments;
3744
3748
for (const auto &solution : solutions) {
3745
3749
auto type = solution.typeBindings .lookup (typeVar);
3750
+ // Type variables gathered from a solution's type binding context may not
3751
+ // exist in another given solution because each solution could have a
3752
+ // different set of overload choices picked, which implies that some of
3753
+ // the generic parameters, and type variables that represent them, would
3754
+ // be unique to that solution.
3755
+ if (!type)
3756
+ continue ;
3757
+
3746
3758
// Contextual opaque result type is uniquely identified by
3747
3759
// declaration it's associated with, so we have to compare
3748
3760
// declarations instead of using pointer equality on such types.
0 commit comments