Appender bug, or impossible?

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Mon Nov 14 12:26:42 PST 2016


On 14.11.2016 00:32, Steven Schveighoffer wrote:
>
> A Foo[] can be stored in a Foo, because it doesn't need the size. But
> yes, as soon as you start needing Appender functions, then the compiler
> chokes.
>
> It is a forward reference bug, but still a bug IMO. If you can store the
> appender, then the compiler knows how big it has to be. So it should be
> fine at that point.
>
> Paging Timon, I'm betting your front end handles this just fine ;)
>
> -Steve

It does. :)

Minimal example:

struct Appender(A){
     alias T = typeof({ A a; return a[0]; }());
     T[] data;
     void put(T item){ data~=item; }
}
struct Foo{ Appender!(Foo[]) fooAppender; }
Foo[] test(){
     Foo f;
     f.fooAppender.put(Foo());
     return f.fooAppender.data;
}
static assert(test().length==1);


Error with DMD, works with my front end.


More information about the Digitalmars-d mailing list