www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23596] New: override deprecated of deprecated base class

https://issues.dlang.org/show_bug.cgi?id=23596

          Issue ID: 23596
           Summary: override deprecated of deprecated base class could
                    work
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P5
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: destructionator gmail.com

I seem to have found a messy scenario. The base class has an old way and a new
way. I want to get the users to migrate to the new way:

-----
class Base {
        deprecated("Use newWay instead") abstract string oldWay();
        abstract string newWay();
}

class Child : Base {
        /+
        // if I keep a compatibility thing I get:
        depre.d(14): Deprecation: `depre.Child.oldWay` is overriding the
deprecated method `depre.Base.oldWay`

        Which is fine, I want the children to know they should migrate,
        but if they do....
        +/
        // override string oldWay() { return newWay(); }

        /+
        // ...if I only implement the new way, I'm stuck:
        depre.d(11): Error: cannot create instance of abstract class `Child`
        depre.d(11):        function `string oldWay()` is not implemented
        +/
        override string newWay() { return "yay"; }

        /+
        // so I'm forced to implement it.  But I want to acknowledge
        // I'm only doing it for the migration and want to forward deprecated
        // and now I get two! warnings:

        depre.d(27): Deprecation: `depre.Child.oldWay` is overriding the
deprecated method `depre.Base.oldWay`
        depre.d(27): Deprecation: `depre.Child.oldWay` cannot be marked as
`deprecated` because it is overriding a function in the base class
        +/
        override deprecated string oldWay() { return newWay(); }
}

void main() {
        auto child = new Child();
}
---


I can't deprecate it without the user code getting more problems. I can't
remove it without breaking the user experience (I really like the compiler
telling them what changed as they use it!)


I can change the base class to remove `abstract` to make it work, but it would
be nice if there was a way to indicate it on the base but also indicate it as
handled on the child; I think an `override deprecated` ought to suppress the
warning and pass it on to the next user.


Probably related to : https://issues.dlang.org/show_bug.cgi?id=17586

--
Jan 03 2023