www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Bug? somearrayofclassinstances.filter(...).array fails because of

reply dom <dschoerk gmx.at> writes:
i just had a scenario like the one below. when calling .array on 
the filterresult dmd goes nuts because of the init() function in 
Players. Renaming to initialize() solved the problem.

Solution: As .init is used for struct initialization and such 
(https://dlang.org/spec/property.html#init) i think it should be 
a restricted keyword for class members and methods

experienced programmers ofc know that .init is used in special 
ways and avoid it. newcomers like me have a hard time with such 
cases.

class Players
{
   void init() { ... }

   ...
}

auto candidates = players.filter!(x => {
   return x.active && x.getName().indexOf(searchstring) > -1;
}).array;
Jul 15 2016
parent reply ag0aep6g <anonymous example.com> writes:
On 07/15/2016 12:54 PM, dom wrote:
 i just had a scenario like the one below. when calling .array on the
 filterresult dmd goes nuts because of the init() function in Players.
 Renaming to initialize() solved the problem.

 Solution: As .init is used for struct initialization and such
 (https://dlang.org/spec/property.html#init) i think it should be a
 restricted keyword for class members and methods
Known issue. https://issues.dlang.org/show_bug.cgi?id=14237 https://issues.dlang.org/show_bug.cgi?id=7066 Of course, being known doesn't mean that anyone is actively working on a fix. Feel free to make (a little) noise on Bugzilla, or in the General group.
Jul 15 2016
parent Steven Schveighoffer <schveiguy yahoo.com> writes:
On 7/15/16 7:44 AM, ag0aep6g wrote:
 On 07/15/2016 12:54 PM, dom wrote:
 i just had a scenario like the one below. when calling .array on the
 filterresult dmd goes nuts because of the init() function in Players.
 Renaming to initialize() solved the problem.

 Solution: As .init is used for struct initialization and such
 (https://dlang.org/spec/property.html#init) i think it should be a
 restricted keyword for class members and methods
Known issue. https://issues.dlang.org/show_bug.cgi?id=14237 https://issues.dlang.org/show_bug.cgi?id=7066 Of course, being known doesn't mean that anyone is actively working on a fix. Feel free to make (a little) noise on Bugzilla, or in the General group.
This is being worked on. The issue is that TypeInfo.init is used by druntime to mean the init data to store for a type. So until that has been deprecated for a long enough time (I don't know the current status, but we are in the process of naming it initializer instead), then we can't fix this issue. -Steve
Jul 18 2016