@@ -5785,6 +5785,41 @@ bool ConstraintSystem::repairFailures(
5785
5785
break;
5786
5786
}
5787
5787
5788
+ // There is no subtyping between object types of inout argument/parameter.
5789
+ if (auto argConv = path.back().getAs<LocatorPathElt::ApplyArgToParam>()) {
5790
+ // Attempt conversions first.
5791
+ if (hasAnyRestriction())
5792
+ break;
5793
+
5794
+ // Unwraps are allowed to preserve l-valueness so we can suggest
5795
+ // them here.
5796
+ if (repairViaOptionalUnwrap(*this, lhs, rhs, matchKind,
5797
+ conversionsOrFixes, locator))
5798
+ return true;
5799
+
5800
+ auto *loc = getConstraintLocator(locator);
5801
+
5802
+ auto result = matchTypes(lhs, rhs, ConstraintKind::Conversion,
5803
+ TMF_ApplyingFix, locator);
5804
+
5805
+ ConstraintFix *fix = nullptr;
5806
+ if (result.isFailure()) {
5807
+ // If this is a "destination" argument to a mutating operator
5808
+ // like `+=`, let's consider it contextual and only attempt
5809
+ // to fix type mismatch on the "source" right-hand side of
5810
+ // such operators.
5811
+ if (isOperatorArgument(loc) && argConv->getArgIdx() == 0)
5812
+ break;
5813
+
5814
+ fix = AllowArgumentMismatch::create(*this, lhs, rhs, loc);
5815
+ } else {
5816
+ fix = AllowInOutConversion::create(*this, lhs, rhs, loc);
5817
+ }
5818
+
5819
+ conversionsOrFixes.push_back(fix);
5820
+ break;
5821
+ }
5822
+
5788
5823
// If this is a problem with result type of a subscript setter,
5789
5824
// let's re-attempt to repair without l-value conversion in the
5790
5825
// locator to fix underlying type mismatch.
@@ -5804,7 +5839,7 @@ bool ConstraintSystem::repairFailures(
5804
5839
break;
5805
5840
}
5806
5841
5807
- LLVM_FALLTHROUGH ;
5842
+ break ;
5808
5843
}
5809
5844
5810
5845
case ConstraintLocator::ApplyArgToParam: {
@@ -5921,33 +5956,6 @@ bool ConstraintSystem::repairFailures(
5921
5956
}
5922
5957
}
5923
5958
5924
- // There is no subtyping between object types of inout argument/parameter.
5925
- if (elt.getKind() == ConstraintLocator::LValueConversion) {
5926
- auto result = matchTypes(lhs, rhs, ConstraintKind::Conversion,
5927
- TMF_ApplyingFix, locator);
5928
-
5929
- ConstraintFix *fix = nullptr;
5930
- if (result.isFailure()) {
5931
- // If this is a "destination" argument to a mutating operator
5932
- // like `+=`, let's consider it contextual and only attempt
5933
- // to fix type mismatch on the "source" right-hand side of
5934
- // such operators.
5935
- if (isOperatorArgument(loc) &&
5936
- loc->findLast<LocatorPathElt::ApplyArgToParam>()->getArgIdx() == 0)
5937
- break;
5938
-
5939
- fix = AllowArgumentMismatch::create(*this, lhs, rhs, loc);
5940
- } else {
5941
- fix = AllowInOutConversion::create(*this, lhs, rhs, loc);
5942
- }
5943
-
5944
- conversionsOrFixes.push_back(fix);
5945
- break;
5946
- }
5947
-
5948
- if (elt.getKind() != ConstraintLocator::ApplyArgToParam)
5949
- break;
5950
-
5951
5959
// If argument in l-value type and parameter is `inout` or a pointer,
5952
5960
// let's see if it's generic parameter matches and suggest adding explicit
5953
5961
// `&`.
0 commit comments