[Issue 19437] New: first boolean operation with a double after 'each!' always true

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Nov 26 13:19:39 UTC 2018


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

          Issue ID: 19437
           Summary: first boolean operation with a double after 'each!'
                    always true
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: dkorpel at live.nl

```
// The magic happens on Windows 32-bit dmd 2.83, no -O/-inline/-m64/Posix/LDC
nothrow: pure: @safe: // for good measure

struct S {
        double num;
}

void main() {
        import std.algorithm: each;
        S[] sList = new S[7];    // with 6 the magic won't happen
        sList.each!(x => x.num); // important
        double two = 2;          // with int the magic won't happen
        assert(two != two, "A");
        assert(two == two, "B");
        assert(two != two, "C");
        assert(two == two, "D");
}
```
Q: Which of the four assertions throws the AssertError?
A: assert C! 

I came across this when tests curiously failed reporting things like "expected
74, was 74". It seems the first condition involving a double after the each!
will be true. In the non-reduced version the each! is even called in a
different method. You can also replace assert A with this:
```
if (two != 2) writeln("2 != ", two);
```
And you will see "2 != 2". But only once, you can't duplicate the if-statement
and expect the same result.

--


More information about the Digitalmars-d-bugs mailing list