D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 23552 - Function `x` does not override any function, but it actually does
Summary: Function `x` does not override any function, but it actually does
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Windows
: P1 enhancement
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2022-12-13 12:26 UTC by Grim Maple
Modified: 2022-12-16 08:07 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Grim Maple 2022-12-13 12:26:11 UTC
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 Grim Maple 2022-12-13 12:33:28 UTC
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 Dlang Bot 2022-12-16 07:23:37 UTC
@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 Dlang Bot 2022-12-16 08:07:57 UTC
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