D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7153 - Compile-time error for randomCover of char[]
Summary: Compile-time error for randomCover of char[]
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2011-12-22 04:47 UTC by bearophile_hugs
Modified: 2014-02-16 14:32 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2011-12-22 04:47:45 UTC
This is wrong D2 code because randomCover is probably unable to use a char[] (while it's able to use a dchar[]). But instead of giving a compile-time error (like sort does if you try to sort a char[]) this produces a run-time error:


import std.stdio, std.random, std.array;
void main() {
    char[] data = "ABCDEF".dup;
    array(randomCover(data, rndGen)); // OK
    writeln(randomCover(data, rndGen)); // runtime error
}


DMD 2.057 gives at run-time:

core.exception.AssertError@std.random(1260): Assertion failure
----------------
...\dmd2\src\phobos\std\format.d(1394): D3std6format240__T11formatValueTS3std5stdio4File17LockingTextWriterTS3std6random156__T11RandomCC5041E8639AC9593490B587E3A11ED51
...\dmd2\src\phobos\std\format.d(2056): D3std6format242__T13formatGenericTS3std5stdio4File17LockingTextWriterTS3std6random156__T11RandoCF38C173958DE37C3A1B1FB41B1E1E4E
...\dmd2\src\phobos\std\format.d(390): D3std6format243__T14formattedWriteTS3std5stdio4File17LockingTextWriterTaTS3std6random156__T11Ra21BBED73A15ED2D7DD23A5859960F47B
...\dmd2\src\phobos\std\stdio.d(680): D3std5stdio4File197__T5writeTS3std6random156__T11RandomCoverTAaTS3std6random98__T21MersenneTwisBA2E7D5419D9E1A48EA3D0223CAF316C
...\dmd2\src\phobos\std\stdio.d(1516): D3std5stdio197__T7writelnTS3std6random156__T11RandomCoverTAaTS3std6random98__T21MersenneTwister3E21F503D8BD64EF969BB07907936D5C
...\test.d(5): _Dmain
----------------
E
Comment 1 Peter Alexander 2014-02-16 14:32:46 UTC
A compile time error since 2.060:

Error: template std.random.randomCover does not match any function template declaration. Candidates are:
...

http://dpaste.dzfl.pl/6a9de69a00b0