[TypeChecker] Extend type inference from default expressions to handle nested generic parameters

Adds support for parameter types like `[T?]` or `[(T, U?)]`,
and relaxes restriction on same-type generic parameters.

A same-type requirement is acceptable if it only includes
in-scope generic parameters and concrete types i.e. `T.X == Int`
if accepted if `T` is referenced only by a parameter default
expression is being applied to.
This commit is contained in:
Pavel Yaskevich
2022-02-18 10:16:39 -08:00
parent a6f86c453d
commit aea76ca358
5 changed files with 339 additions and 77 deletions

View File

@@ -1632,13 +1632,13 @@ static ConstraintSystem::TypeMatchResult matchCallArguments(
if (parameterBindings[paramIdx].empty()) {
auto &ctx = cs.getASTContext();
if (paramTy->isTypeVariableOrMember() &&
if (paramTy->hasTypeVariable() &&
ctx.TypeCheckerOpts.EnableTypeInferenceFromDefaultArguments) {
auto *paramList = getParameterList(callee);
auto defaultExprType = paramList->get(paramIdx)->getTypeOfDefaultExpr();
// A caller side default.
if (!defaultExprType)
if (!defaultExprType || defaultExprType->hasError())
continue;
// If this is just a regular default type that works