Appender bug, or impossible?

Rainer Schuetze via Digitalmars-d digitalmars-d at puremagic.com
Tue Nov 15 05:11:22 PST 2016



On 14.11.2016 21:26, Timon Gehr wrote:
> 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.

Coincidentally, I've tried compiling your front end with latest dmd just 
yesterday. There is one file missing, though: cent_.d. Could you please 
commit this, too?

The cent code commented out, I noticed your code is suffering from the 
same issue as the OP (also happens for AAs, e.g. T[int]). A workaround 
is to use void[] and wrap it in property functions.

I've fixed/worked around a number of issues in dmd with respect to 
incomplete semantic analysis that happen with template mixins, but more 
still pop up afterwards.

Are there limitations to what the front end understands? Is it able to 
digest itself? That would be pretty impressive ;-)


More information about the Digitalmars-d mailing list