www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13083] New: using map() with a delegate which uses a ref


          Issue ID: 13083
           Summary: using map() with a delegate which uses a ref parameter
                    to the enclosing scope is broken when compiling with
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: major
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: maor weka.io

Using dmd 2.065.0 on Linux the following works fine when compiled without
-inline but crashes with a segfault when compiled with -inline

import std.stdio;

int f(ref int[int] hash) {
  int[] ar = [8, 8, 8, 8];
  writefln("result: %s", ar.map!(x => x + hash[x]).reduce!(min));
  return 0;

int main() { 
  int[int] hash = [ 8: 1, 9: 2 ];

  return 0;

reduce is used to force evaluation of the map.

the command lines I used are:

working: dmd -g ./test.d -oftest
broken:  dmd -inline -g ./test.d -oftest

Jul 09 2014