[CSSimplify] Increase contextual element mismatch impact when related to Any{Hashable}

Impact is higher in this case because it means that other collection
or a pattern (in case of for-in loop) is structurally incompatible with
collection's element type.
This commit is contained in:
Pavel Yaskevich
2022-11-01 17:09:43 -07:00
parent 3c0401c7cb
commit cf5d41c6dd

View File

@@ -13850,6 +13850,14 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
impact = 10;
}
// Increase impact of invalid conversions to `Any` and `AnyHashable`
// associated with collection elements (i.e. for-in sequence element)
// because it means that other side is structurally incompatible.
if (fix->getKind() == FixKind::IgnoreCollectionElementContextualMismatch) {
if (type2->isAny() || type2->isAnyHashable())
++impact;
}
if (recordFix(fix, impact))
return SolutionKind::Error;