Appender bug, or impossible?

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Sun Nov 13 15:32:16 PST 2016


On 11/13/16 11:29 AM, Jonathan Marler wrote:
> It looks like an Appender field of a struct doesn't work when its
> element type is the containing struct, i.e.
>
> struct Foo
> {
>    Appender!(Foo[]) fooAppender;
> }
>
> My guess is the problem is that the Appender needs to know how big "Foo"
> is since it would be storing each element by value, but since Foo's size
> depends on the size of the appender, we have a circular dependency on
> knowing the storage size.
>
> This theory is reinforced because modifying the element type of
> fooAppender to "Foo*" fixes the problem.
> struct Foo
> {
>    Appender!(Foo*[]) fooAppender; // Works fine
> }
>
> One odd thing is that this error doesn't manifest until the appender is
> used.  It compiles just fine so long as you don't actually use the
> appender, but once you put something in it or access the data, you will
> get a compiler error at the location where it was used, and not at the
> place where the appender was defined.  I'm not sure how it does this,
> but from the error messages I've seen, it looks like the appender may be
> setting the element type to "void" and silently continuing on as if this
> isn't a problem.

This is probably because Appender's functions are all templates.

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


More information about the Digitalmars-d mailing list