Skip to content

Commit aa286b7

Browse files
committed
[CSSimplify] Check whether parameter refers to generic parameters before attempting inference from default
1 parent aea76ca commit aa286b7

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,17 +1632,24 @@ static ConstraintSystem::TypeMatchResult matchCallArguments(
16321632
if (parameterBindings[paramIdx].empty()) {
16331633
auto &ctx = cs.getASTContext();
16341634

1635-
if (paramTy->hasTypeVariable() &&
1636-
ctx.TypeCheckerOpts.EnableTypeInferenceFromDefaultArguments) {
1635+
if (ctx.TypeCheckerOpts.EnableTypeInferenceFromDefaultArguments) {
16371636
auto *paramList = getParameterList(callee);
1638-
auto defaultExprType = paramList->get(paramIdx)->getTypeOfDefaultExpr();
1637+
auto *PD = paramList->get(paramIdx);
1638+
1639+
// There is nothing to infer if parameter doesn't have any
1640+
// generic parameters in its type.
1641+
if (!PD->getInterfaceType()->hasTypeParameter())
1642+
continue;
1643+
1644+
auto defaultExprType = PD->getTypeOfDefaultExpr();
16391645

16401646
// A caller side default.
16411647
if (!defaultExprType || defaultExprType->hasError())
16421648
continue;
16431649

1644-
// If this is just a regular default type that works
1645-
// for any generic parameter type, let's continue.
1650+
// If this is just a regular default type that should
1651+
// work for all substitutions of generic parameter,
1652+
// let's continue.
16461653
if (defaultExprType->hasArchetype())
16471654
continue;
16481655

0 commit comments

Comments
 (0)