[Issue 15037] New: method TypeInfo.init shadows built-in init property

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Sep 11 04:26:17 PDT 2015


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

          Issue ID: 15037
           Summary: method TypeInfo.init shadows built-in init property
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: druntime
          Assignee: nobody at puremagic.com
          Reporter: ag0aep6g at gmail.com

Found by Rene Zwanenburg:
http://forum.dlang.org/post/xzfnqpkjsxyrebdhzsrz@forum.dlang.org

Reduced test case:
----
static assert(is(typeof(TypeInfo.init) == TypeInfo)); /* fails; should pass */
----

Rene's test case:
----
void main()
{
        import std.algorithm.mutation : remove;

        TypeInfo_Class[] arr;
        TypeInfo_Class c;
        arr = arr.remove!(a => a is c);
}
----

The problem is that TypeInfo defines an "init" method which shadows the
built-in init property. This confuses templates when they expect T.init to be
the init value of T. In Rene's code, ElementType is the one trying to use the
init property.

In my opinion, the compiler should reject members called "init". A quick test
shows that it already rejects "sizeof" and "mangleof".

--


More information about the Digitalmars-d-bugs mailing list