[CSSimplify] Allow converting tuple with pack expansions to Void for closure result

Maintains existing rule where single-expression closure is allowed
to convert to contextual function type with `Void` result.
This commit is contained in:
Pavel Yaskevich
2023-05-10 12:16:35 -07:00
committed by Pavel Yaskevich
parent effa261266
commit dc4ee4b61a
2 changed files with 13 additions and 2 deletions

View File

@@ -6985,6 +6985,14 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
return formUnsolvedResult();
}
// Closure result is allowed to convert to Void in certain circumstances,
// let's forego tuple matching because it is guaranteed to fail and jump
// to `() -> T` to `() -> Void` rule.
if (locator.endsWith<LocatorPathElt::ClosureBody>()) {
if (containsPackExpansionType(tuple1) && tuple2->isVoid())
break;
}
// Add each tuple type to the locator before matching the element types.
// This is useful for diagnostics, because the error message can use the
// full tuple type for several element mismatches. Use the original types