www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13202] New: Don't allow silent shadowing of type properties

https://issues.dlang.org/show_bug.cgi?id=13202

          Issue ID: 13202
           Summary: Don't allow silent shadowing of type properties
           Product: D
           Version: D2
          Hardware: x86
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: davidsp fb.com

A class can accidentally overwrite a type property like T.init by defining a
method init(). This shadowing is silently accepted by the compiler:


class A
{
  void init() {}
}

void t(T)()
{
  auto x = T.init;
}

int main(string[] args)
{
  t!A();
}

-> test.d(10): Error: need 'this' for 'init' of type 'void()'.

The bug is more: "Don't allow shadowing of type properties".

auto x = T.init;

should always be the appropriate initialization value, otherwise templates
cannot savely use T.init if they allow a class or struct to be specified.

--
Jul 24 2014