class MyClass {
        Appender!string _stringBuilder;

        this() {
                _stringBuilder = Appender!string(null);
                _stringBuilder.clear();
        }

        @property string str() {
                return _stringBuilder.data;
        }

        void append(string s) {
                formattedWrite(_stringBuilder, "%s", s);
        }
}

MyClass c = new MyClass();
c.append("text 1");
c.append("__222");

writeln(c.str); //in this case nothing is printed out

Following workarounds work:
1) call _stringBuilder.put() instead of formattedWrite()
2) if "_stringBuilder.clear()" is omitted in the constructor, formattedWrite(...) will work as expected.

Is it a bug or is there a reason for such behaviour?

Reply via email to