[CS] Improve handling of holes for Named/AnyPatterns

Rather than eagerly binding them to holes if the
sequence element type ends up being Any, let's
record the CollectionElementContextualMismatch fix,
and then if the patterns end up becoming holes,
skip penalizing them if we know the fix was
recorded. This avoids prematurely turning type
variables for ExprPatterns into holes, which
should be able to get better bindings from the
expression provided. Also this means we'll apply
the logic to non-Any sequence types, which
previously we would give a confusing diagnostic
to.
This commit is contained in:
Hamish Knight
2023-05-04 14:36:16 +01:00
parent 1be25895b8
commit b07f7b336e
7 changed files with 43 additions and 22 deletions

View File

@@ -669,6 +669,14 @@ ConstraintLocator::isForSingleValueStmtBranch() const {
return SingleValueStmtBranchKind::Regular;
}
NullablePtr<Pattern> ConstraintLocator::getPatternMatch() const {
auto matchElt = findLast<LocatorPathElt::PatternMatch>();
if (!matchElt)
return nullptr;
return matchElt->getPattern();
}
bool ConstraintLocator::isMemberRef() const {
if (isLastElement<LocatorPathElt::Member>()) {
return true;