Bug 19546 – cannot implicitly override base class method [...] add override attribute

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-01-03T21:53:13Z
Last change time
2022-07-23T13:06:45Z
Keywords
spec
Assigned to
No Owner
Creator
kdevel

Comments

Comment #0 by kdevel — 2019-01-03T21:53:13Z
According to https://dlang.org/spec/interface.html #10 this program should compile: ```ifa.d interface D { int foo(); } class A : D { int foo() { return 1; } } class B : A { int foo() { return 2; } } void main () { import std.stdio; B b = new B(); writeln (b.foo()); // returns 2 D d = cast(D) b; // ok since B inherits A's D implementation writeln (d.foo()); // returns 2; } ``` $ dmd ifa ifa.d(13): Error: cannot implicitly override base class method ifa.A.foo with ifa.B.foo; add override attribute $ dmd --version DMD64 D Compiler v2.082.0 Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved written by Walter Bright
Comment #1 by kdevel — 2019-01-03T21:58:36Z
https://dlang.org/spec/interface.html #11 also need the override attribute.
Comment #2 by nick — 2022-07-23T13:06:45Z