www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17331] New: appender can't be use for initialization

https://issues.dlang.org/show_bug.cgi?id=17331

          Issue ID: 17331
           Summary: appender can't be use for initialization
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: bitworld qq.com

Compiler: DMD32 D Compiler v2.074.0
OS: Windows, Ubuntu

Here is my test code.

import std.stdio;
import std.array;

struct PackageHandler
{
    private auto buffer = appender!(ubyte[])();  // The bug is here
    // private Appender!(ubyte[]) buffer;  // It's ok.

    void test()
    {
        assert(buffer.data.length == 0);  // for test
    }

    void append(ubyte[] data)
    {
        buffer ~= data;
    }

    void reset()
    {
        buffer.clear();
    }
}

class AppenderTester
{
    private PackageHandler handler;

    this()
    {
        handler.test();
    }

    void append()
    {
        handler.append([11, 12, 13]);
    }

    void clear()
    {
        handler.reset();
    }
}

void main()
{
    AppenderTester tester01 = new AppenderTester();
    tester01.append();
    // tester01.clear();

    AppenderTester tester02 = new AppenderTester();
}

--
Apr 18