D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7441 - interface allowes empty statics and replace of statics
Summary: interface allowes empty statics and replace of statics
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All Windows
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-05 02:17 UTC by dennis luehring
Modified: 2012-02-05 02:59 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description dennis luehring 2012-02-05 02:17:45 UTC
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 yebblies 2012-02-05 02:23:26 UTC
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 dennis luehring 2012-02-05 02:46:46 UTC
(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 yebblies 2012-02-05 02:59:42 UTC
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)