www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12610] New: std.algorithm.reduce (with seed) and array-wise


          Issue ID: 12610
           Summary: std.algorithm.reduce (with seed) and array-wise
                    operation produces incorrect result
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: acehreli yahoo.com

The following program produces incorrect and random results like [373728176],
[-2022052576], etc.

(Build *without* -inline.)

import std.stdio;
import std.algorithm;

void main()
    int[] arr = [ 0 ];

    int[1] seed;
    int[] result = reduce!((sum, _) => sum[])(seed, arr);

    writefln("%s", result);

Any of the following is sufficient to cover up the issue:

* Building with -inline

* Not slicing sum inside the lambda but returning it directly (i.e. => sum)

* Inserting a writefln expression inside the lambda


Apr 21 2014