@@ -616,20 +616,6 @@ Type TypeChecker::typeCheckParameterDefault(Expr *&defaultValue,
616
616
});
617
617
};
618
618
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
-
633
619
// Anchor of this default expression i.e. function, subscript
634
620
// or enum case.
635
621
auto *anchor = cast<ValueDecl>(DC->getParent ()->getAsDecl ());
@@ -641,14 +627,42 @@ Type TypeChecker::typeCheckParameterDefault(Expr *&defaultValue,
641
627
642
628
if (anchor->hasCurriedSelf ())
643
629
anchorTy = anchorTy->getResult ()->castTo <AnyFunctionType>();
630
+
631
+ auto containsTypesButDependent = [&](Type type) -> bool {
632
+
633
+ class Walker : public TypeWalker {
634
+ llvm::function_ref<TypeVariableType *(GenericTypeParamType *)> findParamFn;
635
+ public:
636
+ explicit Walker (llvm::function_ref<TypeVariableType *(GenericTypeParamType *)> findParam) : findParamFn(findParam) {}
637
+
638
+ Action walkToTypePre (Type ty) override {
639
+ if (auto *GP = ty->getAs <GenericTypeParamType>()) {
640
+ if (findParamFn (GP)) {
641
+ return Action::Stop;
642
+ }
643
+ }
644
+ if (auto *DMT = ty->getAs <DependentMemberType>()) {
645
+ if (auto *baseGP = DMT->getBase ()->getAs <GenericTypeParamType>()) {
646
+ if (findParamFn (baseGP)) {
647
+ return Action::SkipNode;
648
+ }
649
+ }
650
+ }
651
+ return Action::Continue;
652
+ }
653
+ };
654
+
655
+ return type.walk (Walker (findParam));
656
+ };
657
+
644
658
// Reject if generic parameters are used in multiple different positions
645
659
// in the parameter list.
646
660
647
661
llvm::SmallVector<unsigned , 2 > affectedParams;
648
662
for (unsigned i : indices (anchorTy->getParams ())) {
649
663
const auto ¶m = anchorTy->getParams ()[i];
650
664
651
- if (containsTypesButDependant (param.getPlainType ()))
665
+ if (containsTypesButDependent (param.getPlainType ()))
652
666
affectedParams.push_back (i);
653
667
}
654
668
0 commit comments