Bug 7153 – Compile-time error for randomCover of char[]

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2011-12-22T04:47:00Z
Last change time
2014-02-16T14:32:46Z
Keywords
diagnostic
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2011-12-22T04:47:45Z
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: [email protected](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 by peter.alexander.au — 2014-02-16T14:32:46Z
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