Skip to content

[CSBindings] NFC: Diagnose leading-dot inference failure when base type is… #65553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/Sema/CSBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2257,6 +2257,13 @@ TypeVariableBinding::fixForHole(ConstraintSystem &cs) const {
}
}

if (srcLocator->isLastElement<LocatorPathElt::MemberRefBase>()) {
auto *baseExpr = castToExpr<UnresolvedMemberExpr>(srcLocator->getAnchor());
ConstraintFix *fix = SpecifyBaseTypeForContextualMember::create(
cs, baseExpr->getName(), srcLocator);
return std::make_pair(fix, defaultImpact);
}

return None;
}

Expand Down
15 changes: 2 additions & 13 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6185,21 +6185,10 @@ bool ConstraintSystem::repairFailures(
}

case ConstraintLocator::UnresolvedMemberChainResult: {
// Ignore this mismatch if result is already a hole.
if (rhs->isPlaceholder())
// Ignore this mismatch if base or result is already a hole.
if (lhs->isPlaceholder() || rhs->isPlaceholder())
return true;

// The base is a placeholder, let's report an unknown base issue.
if (lhs->isPlaceholder()) {
auto *baseExpr =
castToExpr<UnresolvedMemberChainResultExpr>(anchor)->getChainBase();

auto *fix = SpecifyBaseTypeForContextualMember::create(
*this, baseExpr->getName(), getConstraintLocator(locator));
conversionsOrFixes.push_back(fix);
break;
}

if (repairViaOptionalUnwrap(*this, lhs, rhs, matchKind, conversionsOrFixes,
locator))
return true;
Expand Down