http://d.puremagic.com/issues/show_bug.cgi?id=8085
Summary: std.algorithm.joiner makes invalid assumptions about front() Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: normal Priority: P2 Component: Phobos AssignedTo: nob...@puremagic.com ReportedBy: bugzi...@digitalmars.com --- Comment #0 from Walter Bright <bugzi...@digitalmars.com> 2012-05-11 12:05:54 PDT --- Given the program: ========================= import std.stdio; import std.ascii; import std.algorithm; import std.string; void main() { //stdin.byChunk(1024).joiner().map!(a => toUpper(a)).copy(stdout.lockingTextWriter()); stdin.byLine(KeepTerminator.yes).joiner().map!(a => toUpper(a)).copy(stdout.lockingTextWriter()); //stdin.byLine(KeepTerminator.yes).joiner().copy(stdout.lockingTextWriter()); //stdin.byLine(KeepTerminator.yes).copy(stdout.lockingTextWriter()); } ============================== Compile & run with: foo <foo.d trying one of the 4 versions. Versions 1 and 4 work, 2 and 3 fail horribly. The output is all scrambled, like this: IMPORT STD.ASCII; IMPORT STD.ALGORITIMPORT STD.STRING; M; MPORT STD.STRING; VVOID MAIN() { STDIN.BYLINE(KEEPTERMINATOR.YES).JOINER().MAP!(A => TOUPPER(A)).COPY(STDOUT.LOCKINGTEXT //STDIN.B YLINE(KEEPTERMINATOR.YES).JOINER().COPY(STDOUT.LOCKINGTEXTWRITER()); CKINGTEXTWRITER()); //STDIN.BYLINE(KEEPTERMINATOR.YES).COPY(STDOUT.LOCKINGTEXTWRITER()); ITER()); } //STDIN.BYLINE(KEEPTERMINATOR.YES).COPY(STDOUT.LOCKINGTEXTWRITER()); } Analysis from Andrei: Go to algorithm.d line 2370, when joiner() is defined. Then go down to method prepare(). That method calls _items.front.empty, i.e. it assumes _items.front "works" but at the same time saves _current. At the moment _items.front is called, _current gets overwritten. The code should be changed to not assume that _items.front is independent from _current. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------