| Posted by bearophile_hugs@eml.cc | PermalinkReply |
|
bearophile_hugs@eml.cc
| https://d.puremagic.com/issues/show_bug.cgi?id=12174
Summary: Problems caused by enum predicate with
std.algorithm.sum
Product: D
Version: D2
Platform: x86
OS/Version: Windows
Status: NEW
Keywords: wrong-code
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody@puremagic.com
ReportedBy: bearophile_hugs@eml.cc
--- Comment #0 from bearophile_hugs@eml.cc 2014-02-15 02:46:13 PST ---
I think this is a problem caused by enum predicates:
import std.stdio, std.algorithm, std.range, std.conv;
void main() {
enum foo1 = (int n) => n.text.map!(d => d - '0').reduce!q{a + b};
enum bar1 = iota(1, int.max).filter!(n => n % foo1(n) == 0);
bar1.take(20).writeln; // OK
auto foo2 = (int n) => n.text.map!(d => d - '0').sum;
auto bar2 = iota(1, int.max).filter!(n => n % foo2(n) == 0);
bar2.take(20).writeln; // OK
enum foo3 = (int n) => n.text.map!(d => d - '0').sum;
enum bar3 = iota(1, int.max).filter!(n => n % foo3(n) == 0);
bar3.take(20).writeln; // object.Error: Integer Divide by Zero
}
DMD 2.065beta3 print sat run-time:
object.Error: Integer Divide by Zero
----------------
0x0041F424 in _ULDIV
0x00407DD7 in pure @safe void std.algorithm.FilterResult!(main9__lambda6,
std.range.iota!(int, int).iota(int, int).Result).FilterResult.popFront() at
...\dmd2\src\phobos\std\algorithm.d(1632)
0x00408009 in pure @safe void
std.range.Take!(std.algorithm.FilterResult!(main9__lambda6,
std.range.iota!(int, int).iota(int, int).Result).FilterResult).Take.popFront()
at ...\dmd2\src\phobos\std\range.d(3129)
0x0040882C in
D3std6format194__T11formatRangeTS3std5stdio4File17LockingTextWriterTS3std5range119__T4TakeTS3st88A2D7F05DA1FFDEB975F087094CCBFF
at ...\dmd2\src\phobos\std\format.d(2198)
0x00408763 in
D3std6format194__T11formatValueTS3std5stdio4File17LockingTextWriterTS3std5range119__T4TakeTS3st237782F52D5136BBE0731FA4A3A06E27
at ...\dmd2\src\phobos\std\format.d(2768)
0x004086CC in
D3std6format196__T13formatGenericTS3std5stdio4File17LockingTextWriterTS3std5range119__T4TakeTS3A824662D3C5CD961F4ABE4F8B3D05451
at ...\dmd2\src\phobos\std\format.d(3062)
0x004085E1 in
D3std6format197__T14formattedWriteTS3std5stdio4File17LockingTextWriterTaTS3std5range119__T4Take8E20DD5C0605C68157C9473AF7F4B209
at ...\dmd2\src\phobos\std\format.d(510)
0x004081E4 in
D3std5stdio4File151__T5writeTS3std5range119__T4TakeTS3std9algorithm78__T12FilterResultS14main9_67CA17369C70201CAC91E877226367DB
at ...\dmd2\src\phobos\std\stdio.d(1034)
0x00408143 in
D3std5stdio151__T7writelnTS3std5range119__T4TakeTS3std9algorithm78__T12FilterResultS14main9__laA2546B4D3EC5E436248C74A47438FF6F
at ...\dmd2\src\phobos\std\stdio.d(2345)
0x004020F6 in _Dmain at ...\test.d(11)
0x00408F54 in void rt.dmain2._d_run_main(int, char**, extern (C) int
function(char[][])*).runAll().void __lambda1()
0x00408F27 in void rt.dmain2._d_run_main(int, char**, extern (C) int
function(char[][])*).runAll()
0x00408E40 in _d_run_main
0x00408C6C in main
0x0041F319 in mainCRTStartup
0x779FD2E9 in BaseThreadInitThunk
0x77AD1603 in RtlInitializeExceptionChain
0x77AD15D6 in RtlInitializeExceptionChain
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 18, 20, 21, 24, 27, 30, 36, 40, 42]
[1
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
|