Bug 7441 – interface allowes empty statics and replace of statics

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
Windows
Creation time
2012-02-05T02:17:00Z
Last change time
2012-02-05T02:59:42Z
Assigned to
nobody
Creator
dl.soluz

Comments

Comment #0 by dl.soluz — 2012-02-05T02:17:45Z
import std.stdio; interface itest { static void implemented_static() { writeln("static itest.implemented_static"); } // ok static void empty_static(); // missing implementation } class A: itest { // silently replaces the interface implementation - no warning/error? static void implemented_static() { writeln("static A.implemented_static"); }; // implements the empty static - error? static void empty_static() { writeln("static A.empty_static"); }; } class B: itest { // static becomes silently an method - no warning/error? void implemented_static() { writeln("(method) B.implemented_static"); } // static becomes silently an method - no warning/error? void empty_static() { writeln("(method) B.empty_static"); } } int main() { itest.implemented_static(); //itest.empty_static(); // error A.implemented_static(); A.empty_static(); itest a = new A(); a.implemented_static(); //a.empty_static(); // error B b = new B(); b.implemented_static(); b.empty_static(); return 0; } Tested with dmd2.0.57/Win32
Comment #1 by yebblies — 2012-02-05T02:23:26Z
None of these things are bugs. Methods are allowed to have no body, the body can be provided in a different source/object file and this is resolved at link time. It is not illegal to shadow the name of a static function in a base class/interface.
Comment #2 by dl.soluz — 2012-02-05T02:46:46Z
(In reply to comment #1) > None of these things are bugs. > > Methods are allowed to have no body, the body can be provided in a different > source/object file and this is resolved at link time. > > It is not illegal to shadow the name of a static function in a base > class/interface. and no warning/error or something about the shadowing - but its ok if it is defined like that
Comment #3 by yebblies — 2012-02-05T02:59:42Z
Yes. You can always open an enhancement request, but as C++ supports both these things it's unlikely they will change. (There may already be an enhancement request for the second point)