Bug? somearrayofclassinstances.filter(...).array fails because of .init() method in class

dom via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 15 03:54:21 PDT 2016


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;





More information about the Digitalmars-d-learn mailing list