@@ -6641,21 +6641,21 @@ typecheckDifferentiableAttrforDecl(AbstractFunctionDecl *original,
66416641 // Dynamic `Self` is supported only as a single top-level result for class
66426642 // members. JVP/VJP functions returning `(Self, ...)` tuples would not
66436643 // type-check.
6644- bool diagnoseDynamicSelfResult = original->hasDynamicSelfResult ();
6645- if (diagnoseDynamicSelfResult) {
6646- // Diagnose class initializers in non-final classes.
6647- if (isa<ConstructorDecl>(original)) {
6648- if (!classDecl->isSemanticallyFinal ()) {
6649- diags.diagnose (
6650- attr->getLocation (),
6651- diag::differentiable_attr_nonfinal_class_init_unsupported,
6652- classDecl->getDeclaredInterfaceType ());
6653- attr->setInvalid ();
6654- return nullptr ;
6655- }
6644+ // Diagnose class initializers in non-final classes.
6645+ if (isa<ConstructorDecl>(original)) {
6646+ if (!classDecl->isSemanticallyFinal ()) {
6647+ diags.diagnose (
6648+ attr->getLocation (),
6649+ diag::differentiable_attr_nonfinal_class_init_unsupported,
6650+ classDecl->getDeclaredInterfaceType ());
6651+ attr->setInvalid ();
6652+ return nullptr ;
66566653 }
6654+ }
6655+
6656+ if (auto *funcDecl = dyn_cast<FuncDecl>(original)) {
66576657 // Diagnose all other declarations returning dynamic `Self`.
6658- else {
6658+ if (funcDecl-> getResultInterfaceType ()-> hasDynamicSelfType ()) {
66596659 diags.diagnose (
66606660 attr->getLocation (),
66616661 diag::
@@ -7035,19 +7035,19 @@ static bool typeCheckDerivativeAttr(DerivativeAttr *attr) {
70357035 // Dynamic `Self` is supported only as a single top-level result for class
70367036 // members. JVP/VJP functions returning `(Self, ...)` tuples would not
70377037 // type-check.
7038- bool diagnoseDynamicSelfResult = originalAFD->hasDynamicSelfResult ();
7039- if (diagnoseDynamicSelfResult) {
7038+ if (isa<ConstructorDecl>(originalAFD)) {
70407039 // Diagnose class initializers in non-final classes.
7041- if (isa<ConstructorDecl>(originalAFD)) {
7042- if (!classDecl->isSemanticallyFinal ()) {
7043- diags.diagnose (attr->getLocation (),
7044- diag::derivative_attr_nonfinal_class_init_unsupported,
7045- classDecl->getDeclaredInterfaceType ());
7046- return true ;
7047- }
7040+ if (!classDecl->isSemanticallyFinal ()) {
7041+ diags.diagnose (attr->getLocation (),
7042+ diag::derivative_attr_nonfinal_class_init_unsupported,
7043+ classDecl->getDeclaredInterfaceType ());
7044+ return true ;
70487045 }
7046+ }
7047+
7048+ if (auto *FD = dyn_cast<FuncDecl>(originalAFD)) {
70497049 // Diagnose all other declarations returning dynamic `Self`.
7050- else {
7050+ if (FD-> getResultInterfaceType ()-> hasDynamicSelfType ()) {
70517051 diags.diagnose (
70527052 attr->getLocation (),
70537053 diag::derivative_attr_class_member_dynamic_self_result_unsupported,
0 commit comments