Skip to content

Commit 2d1f9d3

Browse files
committed
[CSSimplify] Move inout failures handing to LValueConversion block
This is cleanup that allows us to avoid a fallthrough to `ApplyArgToParam` handling for `inout` failures.
1 parent ded6158 commit 2d1f9d3

File tree

1 file changed

+36
-28
lines changed

1 file changed

+36
-28
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5785,6 +5785,41 @@ bool ConstraintSystem::repairFailures(
57855785
break;
57865786
}
57875787

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+
57885823
// If this is a problem with result type of a subscript setter,
57895824
// let's re-attempt to repair without l-value conversion in the
57905825
// locator to fix underlying type mismatch.
@@ -5804,7 +5839,7 @@ bool ConstraintSystem::repairFailures(
58045839
break;
58055840
}
58065841

5807-
LLVM_FALLTHROUGH;
5842+
break;
58085843
}
58095844

58105845
case ConstraintLocator::ApplyArgToParam: {
@@ -5921,33 +5956,6 @@ bool ConstraintSystem::repairFailures(
59215956
}
59225957
}
59235958

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-
59515959
// If argument in l-value type and parameter is `inout` or a pointer,
59525960
// let's see if it's generic parameter matches and suggest adding explicit
59535961
// `&`.

0 commit comments

Comments
 (0)