Skip to content

Commit dcd7469

Browse files
committed
[ConstraintSystem] Mark member result type as a potential hole if base was incorrect
If it has been established that member found via static member lookup on protocol metatype doesn't have correct result type, chain's result type the should be treated as a hole.
1 parent d1ab178 commit dcd7469

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,32 @@ void PotentialBindings::finalize(
432432
FullyBound = true;
433433
}
434434
}
435+
436+
if (cs.shouldAttemptFixes() &&
437+
locator->isLastElement<LocatorPathElt::UnresolvedMemberChainResult>()) {
438+
// Let's see whether this chain is valid, is it isn't then to avoid
439+
// diagnosing the same issue multiple different ways, let's infer
440+
// result of the chain to be a hole.
441+
auto *resultExpr =
442+
castToExpr<UnresolvedMemberChainResultExpr>(locator->getAnchor());
443+
auto *baseLocator = cs.getConstraintLocator(
444+
resultExpr->getChainBase(), ConstraintLocator::UnresolvedMember);
445+
446+
if (cs.hasFixFor(
447+
baseLocator,
448+
FixKind::AllowInvalidStaticMemberRefOnProtocolMetatype)) {
449+
cs.recordPotentialHole(TypeVar);
450+
// Clear all of the previously inferred bindings which are inferred
451+
// from inside of a member chain.
452+
Bindings.erase(
453+
llvm::remove_if(
454+
Bindings,
455+
[](const ConstraintSystem::PotentialBinding &binding) {
456+
return binding.Kind == AllowedBindingKind::Supertypes;
457+
}),
458+
Bindings.end());
459+
}
460+
}
435461
}
436462
}
437463

lib/Sema/CSSimplify.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4556,6 +4556,10 @@ bool ConstraintSystem::repairFailures(
45564556
}
45574557

45584558
case ConstraintLocator::UnresolvedMemberChainResult: {
4559+
// Ignore this mismatch if result is already a hole.
4560+
if (rhs->isHole())
4561+
return true;
4562+
45594563
if (repairViaOptionalUnwrap(*this, lhs, rhs, matchKind, conversionsOrFixes,
45604564
locator))
45614565
break;

0 commit comments

Comments
 (0)