[Issue 13202] New: Don't allow silent shadowing of type properties
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Thu Jul 24 18:05:13 PDT 2014
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 at puremagic.com
Reporter: davidsp at 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.
--
More information about the Digitalmars-d-bugs
mailing list