www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12174] New: Problems caused by enum predicate with std.algorithm.sum

reply d-bugmail puremagic.com writes:
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: -------
Feb 15 2014
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12174


monarchdodra gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice
                 CC|                            |monarchdodra gmail.com
           Severity|normal                      |regression


--- Comment #1 from monarchdodra gmail.com 2014-02-27 04:46:40 PST ---
I have no idea what is going on, but on 2.065, I get:

main.d(7): Error: no property 'sum' for type 'MapResult!(__lambda2, string)'
main.d(10): Error: no property 'sum' for type 'MapResult!(__lambda2, string)'
Assertion failure: '0' on line 357 in file 'interpret.c'

abnormal program termination

Also on windows x86. Not sure what happened: I don't really understand your
code, but why isn't it even compiling anymore? 

In any case, adding ice and reg.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 27 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12174


Vladimir Panteleev <thecybershadow gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |thecybershadow gmail.com


--- Comment #2 from Vladimir Panteleev <thecybershadow gmail.com> 2014-03-19
06:39:22 EET ---
(In reply to comment #0)
 DMD 2.065beta3 print sat run-time:

How can this be 2.065beta3 if that version did not yet have the "sum" function at all? -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 18 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12174


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #3 from Kenji Hara <k.hara.pg gmail.com> 2014-04-06 05:51:24 PDT ---
(In reply to comment #1)
 I have no idea what is going on, but on 2.065, I get:
 
 main.d(7): Error: no property 'sum' for type 'MapResult!(__lambda2, string)'
 main.d(10): Error: no property 'sum' for type 'MapResult!(__lambda2, string)'
 Assertion failure: '0' on line 357 in file 'interpret.c'
 
 abnormal program termination
 
 Also on windows x86. Not sure what happened: I don't really understand your
 code, but why isn't it even compiling anymore? 
 
 In any case, adding ice and reg.

The ICE regression is caused from 2.064. https://github.com/D-Programming-Language/dmd/pull/3426 -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 06 2014