@@ -5014,32 +5014,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
50145014
50155015 void visitModuleDecl (ModuleDecl *) { }
50165016
5017- // / Adjust the type of the given declaration to appear as if it were
5018- // / in the given subclass of its actual declared class.
5019- static Type adjustSuperclassMemberDeclType (TypeChecker &TC,
5020- const ValueDecl *decl,
5021- Type subclass) {
5022- ClassDecl *superclassDecl =
5023- decl->getDeclContext ()->getDeclaredTypeInContext ()
5024- ->getClassOrBoundGenericClass ();
5025- auto superclass = subclass;
5026- while (superclass->getClassOrBoundGenericClass () != superclassDecl)
5027- superclass = TC.getSuperClassOf (superclass);
5028- auto type = TC.substMemberTypeWithBase (decl->getModuleContext (), decl,
5029- superclass,
5030- /* isTypeReference=*/ false );
5031- if (auto func = dyn_cast<FuncDecl>(decl)) {
5032- if (func->hasDynamicSelf ()) {
5033- type = type->replaceCovariantResultType (subclass,
5034- func->getNumParameterLists ());
5035- }
5036- } else if (isa<ConstructorDecl>(decl)) {
5037- type = type->replaceCovariantResultType (subclass, /* uncurryLevel=*/ 2 );
5038- }
5039-
5040- return type;
5041- }
5042-
50435017 // / Perform basic checking to determine whether a declaration can override a
50445018 // / declaration in a superclass.
50455019 static bool areOverrideCompatibleSimple (ValueDecl *decl,
@@ -5093,15 +5067,15 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
50935067
50945068 static bool
50955069 diagnoseMismatchedOptionals (TypeChecker &TC,
5096- const Decl *member,
5070+ const ValueDecl *member,
50975071 const ParameterList *params,
50985072 TypeLoc resultTL,
50995073 const ValueDecl *parentMember,
51005074 Type owningTy,
51015075 bool treatIUOResultAsError) {
51025076 bool emittedError = false ;
5103- Type plainParentTy = adjustSuperclassMemberDeclType (TC, parentMember,
5104- owningTy );
5077+ Type plainParentTy = owningTy-> adjustSuperclassMemberDeclType (
5078+ member, parentMember, parentMember-> getInterfaceType (), &TC );
51055079 const auto *parentTy = plainParentTy->castTo <AnyFunctionType>();
51065080 if (isa<AbstractFunctionDecl>(parentMember))
51075081 parentTy = parentTy->getResult ()->castTo <AnyFunctionType>();
@@ -5538,8 +5512,8 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
55385512
55395513 // Check whether the types are identical.
55405514 // FIXME: It's wrong to use the uncurried types here for methods.
5541- auto parentDeclTy = adjustSuperclassMemberDeclType (TC, parentDecl,
5542- owningTy );
5515+ auto parentDeclTy = owningTy-> adjustSuperclassMemberDeclType (
5516+ decl, parentDecl, parentDecl-> getInterfaceType (), &TC );
55435517 parentDeclTy = parentDeclTy->getUnlabeledType (TC.Context );
55445518 if (method) {
55455519 parentDeclTy = parentDeclTy->castTo <AnyFunctionType>()->getResult ();
@@ -5807,8 +5781,8 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
58075781 }
58085782 } else if (auto property = dyn_cast_or_null<VarDecl>(abstractStorage)) {
58095783 auto propertyTy = property->getInterfaceType ();
5810- auto parentPropertyTy = adjustSuperclassMemberDeclType (TC, matchDecl,
5811- superclass );
5784+ auto parentPropertyTy = superclass-> adjustSuperclassMemberDeclType (
5785+ decl, matchDecl, matchDecl-> getInterfaceType (), &TC );
58125786
58135787 if (!propertyTy->canOverride (parentPropertyTy,
58145788 OverrideMatchMode::Strict,
0 commit comments