Comment #0 by joseph.wakeling — 2014-06-01T14:10:10Z
Created attachment 1359
Code snippet illustrating the problem
std.random.uniform will fail to compile if an open lower bound is specified (i.e. boundaries == "(]" or "()") and either:
* the type requested is a character type, or
* the type requested is an integral type smaller than int (i.e. ushort, short, ubyte, byte).
The attached code sample will allow the problem to be seen: attempting to compile it results in errors:
/opt/dmd/import/std/random.d(1336): Error: cannot implicitly convert expression (cast(int)a + 1) of type int to ushort
/opt/dmd/import/std/random.d(1197): Error: template instance std.random.uniform!("()", ushort, ushort, MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 7LU, 2636928640u, 15LU, 4022730752u, 18LU)) error instantiating
uniform.d(10): instantiated from here: uniform!("()", ushort, ushort)
uniform.d(21): instantiated from here: uniformTest!ushort
... and so on for the other unsupported types.
Note that this problem persists whether the uniform() is the recently-updated one provide in PR 1717 or the uniform preceding it, so we can't simply solve the problem by reverting a patch.
Comment #1 by joseph.wakeling — 2014-06-01T14:39:56Z
If we look at the problematic line in the _old_ std.random (i.e. before PR 1717 was merged), we have the following:
ResultType min = cast(ResultType) a + 1;
I'm presuming that this is probably simply a typo and that line should read,
ResultType min = cast(ResultType) (a + 1);
.... ?
Comment #2 by joseph.wakeling — 2014-06-01T15:28:25Z