www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7153] New: Compile-time error for randomCover of char[]

http://d.puremagic.com/issues/show_bug.cgi?id=7153

           Summary: Compile-time error for randomCover of char[]
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: diagnostic
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 22 2011