Appender bug, or impossible?

Jonathan Marler via Digitalmars-d digitalmars-d at puremagic.com
Sun Nov 13 08:29:28 PST 2016


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.

Does anything know if this is a bug, or if it is as designed?  If 
it turns out that the functionality can't be supported, I think 
that not throwing an error at the location of the appender 
definition is a problem that should be addressed.


More information about the Digitalmars-d mailing list