@@ -6641,21 +6641,21 @@ typecheckDifferentiableAttrforDecl(AbstractFunctionDecl *original,
6641
6641
// Dynamic `Self` is supported only as a single top-level result for class
6642
6642
// members. JVP/VJP functions returning `(Self, ...)` tuples would not
6643
6643
// 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 ;
6656
6653
}
6654
+ }
6655
+
6656
+ if (auto *funcDecl = dyn_cast<FuncDecl>(original)) {
6657
6657
// Diagnose all other declarations returning dynamic `Self`.
6658
- else {
6658
+ if (funcDecl-> getResultInterfaceType ()-> hasDynamicSelfType ()) {
6659
6659
diags.diagnose (
6660
6660
attr->getLocation (),
6661
6661
diag::
@@ -7035,19 +7035,19 @@ static bool typeCheckDerivativeAttr(DerivativeAttr *attr) {
7035
7035
// Dynamic `Self` is supported only as a single top-level result for class
7036
7036
// members. JVP/VJP functions returning `(Self, ...)` tuples would not
7037
7037
// type-check.
7038
- bool diagnoseDynamicSelfResult = originalAFD->hasDynamicSelfResult ();
7039
- if (diagnoseDynamicSelfResult) {
7038
+ if (isa<ConstructorDecl>(originalAFD)) {
7040
7039
// 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 ;
7048
7045
}
7046
+ }
7047
+
7048
+ if (auto *FD = dyn_cast<FuncDecl>(originalAFD)) {
7049
7049
// Diagnose all other declarations returning dynamic `Self`.
7050
- else {
7050
+ if (FD-> getResultInterfaceType ()-> hasDynamicSelfType ()) {
7051
7051
diags.diagnose (
7052
7052
attr->getLocation (),
7053
7053
diag::derivative_attr_class_member_dynamic_self_result_unsupported,
0 commit comments