Bug 23596 – override deprecated of deprecated base class could work
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P5
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-01-03T20:47:47Z
Last change time
2023-01-04T13:26:41Z
Assigned to
No Owner
Creator
Adam D. Ruppe
Comments
Comment #0 by destructionator — 2023-01-03T20:47:47Z
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
Comment #1 by razvan.nitu1305 — 2023-01-04T12:06:13Z
> 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
If I understand correctly, you want this code:
class Base
{
deprecated("Use newWay instead") abstract string oldWay();
abstract string newWay();
}
class Child : Base
{
override string newWay() { return "yay"; }
override deprecated string oldWay() { return newWay(); }
}
void main()
{
auto child = new Child();
}
To compile gracefully? If that is the case, then this already happens in the latest master.
Comment #2 by destructionator — 2023-01-04T13:21:46Z
oh nice, then already fixed somehow since the previous release.