Skip to content

Commit 0a10736

Browse files
[Sema] Avoid eargly record an apply arg mismatch for fn param type mismatch involving l-values
1 parent 32ca2fc commit 0a10736

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4092,11 +4092,23 @@ bool ConstraintSystem::repairFailures(
40924092
path.pop_back();
40934093
// If this is a contextual mismatch between l-value types e.g.
40944094
// `@lvalue String vs. @lvalue Int`, let's pretend that it's okay.
4095-
if (!path.empty() && path.back().is<LocatorPathElt::ContextualType>()) {
4096-
auto *locator = getConstraintLocator(anchor, path.back());
4097-
conversionsOrFixes.push_back(
4098-
IgnoreContextualType::create(*this, lhs, rhs, locator));
4099-
break;
4095+
if (!path.empty()) {
4096+
if (path.back().is<LocatorPathElt::ContextualType>()) {
4097+
auto *locator = getConstraintLocator(anchor, path.back());
4098+
conversionsOrFixes.push_back(
4099+
IgnoreContextualType::create(*this, lhs, rhs, locator));
4100+
break;
4101+
}
4102+
4103+
// If this is a function type param type mismatch in any position,
4104+
// the mismatch we want to report is for the whole structural type.
4105+
auto last = std::find_if(
4106+
path.rbegin(), path.rend(), [](LocatorPathElt &elt) -> bool {
4107+
return elt.is<LocatorPathElt::FunctionArgument>();
4108+
});
4109+
4110+
if (last != path.rend())
4111+
break;
41004112
}
41014113

41024114
LLVM_FALLTHROUGH;

0 commit comments

Comments
 (0)