D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 15037 - method TypeInfo.init shadows built-in init property
Summary: method TypeInfo.init shadows built-in init property
Status: RESOLVED DUPLICATE of issue 12233
Alias: None
Product: D
Classification: Unclassified
Component: druntime (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: ag0aep6g
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-09-11 11:26 UTC by ag0aep6g
Modified: 2015-10-08 05:19 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description ag0aep6g 2015-09-11 11:26:17 UTC
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".
Comment 1 ag0aep6g 2015-10-07 17:37:19 UTC
Pull request to start fixing this by renaming the method to "initializer":
https://github.com/D-Programming-Language/druntime/pull/1403
Comment 2 ag0aep6g 2015-10-08 05:19:06 UTC

*** This issue has been marked as a duplicate of issue 12233 ***