D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6789 - std.stdio.File + ternary = bug
Summary: std.stdio.File + ternary = bug
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2011-10-07 16:48 UTC by David Simcha
Modified: 2016-08-09 21:58 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description David Simcha 2011-10-07 16:48:04 UTC
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 SomeDude 2012-04-23 03:58:17 UTC
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 github-bugzilla 2014-03-15 20:40:25 UTC
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 ag0aep6g 2016-08-09 21:58:23 UTC
2.065 exhibits the bug. 2.066 and 2.067 throw some AssertError. Since 2.068 the program prints "false" twice. Closing as WORKSFORME.