Bug 6789 – std.stdio.File + ternary = bug

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2011-10-07T16:48:00Z
Last change time
2016-08-09T21:58:23Z
Keywords
wrong-code
Assigned to
nobody
Creator
dsimcha

Comments

Comment #0 by dsimcha — 2011-10-07T16:48:04Z
I haven't been able to reduce this far enough to know for sure whether this is a DMD or Phobos bug, but the following ternary operator expression should work: import std.stdio; void main() { bool foo; auto lines = (foo ? File("test.d") : File("test.d")).byLine(); writeln(lines.empty); // true auto handle = File("test.d"); lines = handle.byLine(); writeln(lines.empty); // false }
Comment #1 by lovelydear — 2012-04-23T03:58:17Z
This is not a bug. The test actually works if the file "test.d" exists beforehand. If it doesn't exist, one must open the file in write mode. By default, the file is open in read mode. This works as intended. import std.stdio; void main() { bool foo; auto lines = (foo ? File("test.d", "w") : File("test.d", "w")).byLine(); writeln(lines.empty); // true auto handle = File("test.d"); lines = handle.byLine(); writeln(lines.empty); // false }
Comment #2 by github-bugzilla — 2014-03-15T20:40:25Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/ca6643e4c20100419e50c5500396aa3b8021f806 Add IntervalExp and fix parser, and disabled test for issue 6789 All of N-dimensional array operations are now translated to ArrayExp. But currently they are immediately translated to SliceExp, so have no effect.
Comment #3 by ag0aep6g — 2016-08-09T21:58:23Z
2.065 exhibits the bug. 2.066 and 2.067 throw some AssertError. Since 2.068 the program prints "false" twice. Closing as WORKSFORME.