www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18927] New: Regression: Number with real suffix "L" sometimes

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

          Issue ID: 18927
           Summary: Regression: Number with real suffix "L" sometimes
                    fails to compile
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Mac OS X
            Status: NEW
          Severity: minor
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: meapineapple gmail.com

I have a unit test that looks like this:

https://github.com/pineapplemachine/mach.d/blob/master/mach/text/numeric/floats.d#L482

unittest{ /// Parse float
    alias numbers = Aliases!(
        "0.0", "0.0000", "000.0000000000000000000000000",
        "0.25", "0.025", "0.0005", "0.00000000000000005",
        "1", "1.0", "10", "10.0", "11", "11.1", "11.11",
"1111.111111111111111",
        "2", "20", "200", "20000001", "123456", "123.456", "789.123456",
        "1e0", "1e1", "1e2", "1e3", "1e4", "1e5", "1e100", "1e200", "1e2000",
        "1e+0", "1e+1", "1e+2", "1e+3", "1e+4", "1e+5", "1e+100", "1e+200",
"1e+2000",
        "1e-0", "1e-1", "1e-2", "1e-3", "1e-4", "1e-5", "1e-100", "1e-200",
"1e-2000",
        "2e2", "123e4", "123456e7", "1.12313241e12", "1.1e-100",
"111.111111111111e-100",
        "1e01", "01e01", ".01", ".0002"
    );
    foreach(numberstr; numbers){
        // Reals not included here because compiler and implementation output
        // occassionally differ, and which output is more accurate varies.
        foreach(T; Aliases!(double, float)){
            mixin(`T a = ` ~ numberstr ~ `L;`);
            mixin(`T b = -` ~ numberstr ~ `L;`);
            immutable parseda = parsefloat!T(numberstr);
            immutable parsedb = parsefloat!T(`+` ~ numberstr);
            immutable parsedc = parsefloat!T(`-` ~ numberstr);
            assert(fidentical(parseda, a));
            assert(fidentical(parsedb, a));
            assert(fidentical(parsedc, b));
        }
    }
}

The test compiled and passed with DMD 0.072.0. I switched to
dmd-master-2018-05-28 and I got this compile error:

/Users/pineapple/Dropbox/Projects/mach.d/mach/text/numeric/floats.d-mixin-498(498):
Error: cannot implicitly convert expression 20000001L of type long to float
/Users/pineapple/Dropbox/Projects/mach.d/mach/text/numeric/floats.d-mixin-499(499):
Error: cannot implicitly convert expression -20000001L of type long to float

I have not been able to make a smaller repro case. This example program, for
example, compiles without error and prints the expected value:

import std.stdio;
unittest{
    alias T = double;
    double n = 20000001L;
    writeln(n);
}

--
May 31 2018