Skip to content

Commit bde2e9d

Browse files
authored
Update TypeCheckConstraints.cpp
1 parent 7ab9ab9 commit bde2e9d

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,20 @@ Type TypeChecker::typeCheckParameterDefault(Expr *&defaultValue,
616616
});
617617
};
618618

619+
auto containsTypesButDependant = [&](Type type) -> bool {
620+
DependentMemberType *cachedDP = nullptr;
621+
return type.findIf([&](Type type) -> bool {
622+
if (auto *GP = type->getAs<GenericTypeParamType>()) {
623+
if (cachedDP && !cachedDP->getBase()->isEqual(GP))
624+
return findParam(GP);
625+
return cachedDP == nullptr && findParam(GP);
626+
}
627+
if (auto *DP = type->getAs<DependentMemberType>())
628+
cachedDP = DP;
629+
return false;
630+
});
631+
};
632+
619633
// Anchor of this default expression i.e. function, subscript
620634
// or enum case.
621635
auto *anchor = cast<ValueDecl>(DC->getParent()->getAsDecl());
@@ -634,7 +648,7 @@ Type TypeChecker::typeCheckParameterDefault(Expr *&defaultValue,
634648
for (unsigned i : indices(anchorTy->getParams())) {
635649
const auto &param = anchorTy->getParams()[i];
636650

637-
if (containsTypes(param.getPlainType()))
651+
if (containsTypesButDependant(param.getPlainType()))
638652
affectedParams.push_back(i);
639653
}
640654

0 commit comments

Comments
 (0)