Skip to content

Commit 42f80fb

Browse files
committed
[CSSimplify] Teach specialization constraint to look through non-generic typealiases
If type alias declaration doesn't add new generic parameters refer to its underlying type to find them.
1 parent 50d2f4d commit 42f80fb

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13595,15 +13595,36 @@ ConstraintSystem::simplifyExplicitGenericArgumentsConstraint(
1359513595
}
1359613596

1359713597
decl = overloadChoice.getDecl();
13598+
1359813599
auto openedOverloadTypes = getOpenedTypes(overloadLocator);
1359913600
openedTypes.append(openedOverloadTypes.begin(), openedOverloadTypes.end());
1360013601
}
1360113602

13602-
auto genericContext = decl->getAsGenericContext();
13603-
if (!genericContext)
13603+
std::function<GenericParamList *(ValueDecl *)> getGenericParams =
13604+
[&](ValueDecl *decl) -> GenericParamList * {
13605+
auto genericContext = decl->getAsGenericContext();
13606+
if (!genericContext)
13607+
return nullptr;
13608+
13609+
auto genericParams = genericContext->getGenericParams();
13610+
if (!genericParams || genericParams->size() == 0) {
13611+
// If declaration is a non-generic typealias, let's point
13612+
// to the underlying generic declaration.
13613+
if (auto *TA = dyn_cast<TypeAliasDecl>(decl)) {
13614+
if (TA->isGeneric())
13615+
return nullptr;
13616+
if (auto underlying = TA->getUnderlyingType()->getAnyNominal())
13617+
return getGenericParams(underlying);
13618+
}
13619+
}
13620+
13621+
return genericParams;
13622+
};
13623+
13624+
if (!decl->getAsGenericContext())
1360413625
return SolutionKind::Error;
1360513626

13606-
auto genericParams = genericContext->getGenericParams();
13627+
auto genericParams = getGenericParams(decl);
1360713628
if (!genericParams || genericParams->size() == 0) {
1360813629
// FIXME: Record an error here that we're ignoring the parameters.
1360913630
return SolutionKind::Solved;

0 commit comments

Comments
 (0)