A Riddle: what is wrong with this code using std.array.Appender?

user1234 user12324 at 12.de
Mon Mar 25 15:52:49 UTC 2019


On Monday, 25 March 2019 at 14:58:08 UTC, FeepingCreature wrote:
> class Class
> {
>     Appender!(int[]) app = null;
> }
>
> This is the most evil bug I've seen this year yet.
>
> Hint: Appender is a struct, not a class. So what does "= null" 
> do, when it appears as a default initializer?

My bet is that null is converted to int[]

///
class Class
{
     enum int[] initializer = null;
     Appender!(int[]) app0 = initializer;
     Appender!(int[]) app1 = null;
     this()
     {
         assert(app0 == app1);
     }
}

void main()
{
     new Class;
}
///

because Appender ctor can take a int[] i.e a range, no only a 
single elem.


More information about the Digitalmars-d mailing list