Bug 23552 – Function `x` does not override any function, but it actually does

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2022-12-13T12:26:11Z
Last change time
2022-12-16T08:07:57Z
Keywords
pull
Assigned to
No Owner
Creator
Grim Maple

Comments

Comment #0 by grimmaple95 — 2022-12-13T12:26:11Z
Consider code below: ``` import std; abstract class Base { void foo(); } class Derived : Base { void foo() { writeln("foo"); } int data() { return 0; } } class DerivedX : Derived { override int data() { return 1; } } ``` The main issue with this code is missing `override` for `Derived`'s `foo` function. However, this code produces two errors: ``` onlineapp.d(10): Error: cannot implicitly override base class method `onlineapp.Base.foo` with `onlineapp.Derived.foo`; add `override` attribute onlineapp.d(23): Error: function `onlineapp.DerivedX.data` does not override any function ``` The first error is entirely coorect. But the other one is completely wrong. If `override` is added, then the second error is gone too.
Comment #1 by grimmaple95 — 2022-12-13T12:33:28Z
Similar issue happens with below code: ``` import std; class Base { final void foo() { } } class Derived : Base { override void foo() { writeln("foo"); } int data() { return 0; } } class DerivedX : Derived { override int data() { return 1; } } ``` Error output: ``` onlineapp.d(10): Error: function `onlineapp.Derived.foo` cannot override `final` function `onlineapp.Base.foo` onlineapp.d(10): Error: function `void onlineapp.Derived.foo()` does not override any function, did you mean to override `void onlineapp.Base.foo()`? onlineapp.d(16): Error: function `onlineapp.DerivedX.data` does not override any function ```
Comment #2 by dlang-bot — 2022-12-16T07:23:37Z
@RazvanN7 created dlang/dmd pull request #14704 "Fix Issue 23552 - Function x does not override any function, but it actually does" fixing this issue: - Fix Issue 23552 - Function x does not override any function, but it actually does https://github.com/dlang/dmd/pull/14704
Comment #3 by dlang-bot — 2022-12-16T08:07:57Z
dlang/dmd pull request #14704 "Fix Issue 23552 - Function x does not override any function, but it actually does" was merged into master: - 6519d75e986a68ef19904dd5bce7d41b7829436d by RazvanN7: Fix Issue 23552 - Function x does not override any function, but it actually does https://github.com/dlang/dmd/pull/14704