[CSSimplify] Make solver behavior consistent with TypeCheckPattern for paren patterns

A single paren pattern becomes a labeled tuple pattern
e.g. `case .test(let value):` should be able to match
`case test(result: Int)`. Note that it also means that:
`cast test(result: (String, Int))` would be matched against
e.g. `case .test((let x, let y))` but that fails during
pattern coercion (behavior consistent with what happens in
`TypeCheckPattern`).
This commit is contained in:
Pavel Yaskevich
2021-09-25 11:42:18 -07:00
parent 50e70fb3f5
commit 7a854ee1cc

View File

@@ -2290,9 +2290,29 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
increaseScore(SK_FunctionConversion);
}
}
} else if (last->getKind() == ConstraintLocator::PatternMatch &&
isa<EnumElementPattern>(
last->castTo<LocatorPathElt::PatternMatch>().getPattern())) {
} else if (last->is<LocatorPathElt::PatternMatch>() &&
isa<EnumElementPattern>(
last->castTo<LocatorPathElt::PatternMatch>()
.getPattern())) {
// A single paren pattern becomes a labeled tuple pattern
// e.g. `case .test(let value):` should be able to match
// `case test(result: Int)`. Note that it also means that:
// `cast test(result: (String, Int))` would be matched against
// e.g. `case .test((let x, let y))` but that fails during
// pattern coercion (behavior consistent with what happens in
// `TypeCheckPattern`).
if (func1Params.size() == 1 && !func1Params.front().hasLabel() &&
func2Params.size() == 1 && func2Params.front().hasLabel()) {
auto param = func1Params.front();
auto label = func2Params.front().getLabel();
auto labeledParam = FunctionType::Param(param.getPlainType(), label,
param.getParameterFlags());
func1Params.clear();
func1Params.push_back(labeledParam);
}
// Consider following example:
//
// enum E {