www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14833] New: Nested delegates problem

https://issues.dlang.org/show_bug.cgi?id=14833

          Issue ID: 14833
           Summary: Nested delegates problem
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: bearophile_hugs eml.cc

void main() {
    import std.algorithm: map;
    import std.range: iota;
    import std.typecons: tuple;
    auto r1 = 100.iota.map!(a3 => iota(1, a3).map!(a2 => iota(1, a3).map!(a1 =>
tuple(a1, a2, a3)))); // OK
    auto r2 = 100.iota.map!(a3 => iota(1, a3).map!(a2 => iota(1, a2).map!(a1 =>
tuple(a1, a2, a3)))); // Error
}


dmd v2.068.0-b1 gives:

test.d(6,95): Error: delegate
test.main.__lambda2!int.__lambda2.__lambda2!int.__lambda2.__lambda2 cannot
access frame of function test.main.__lambda2
...\dmd2\src\phobos\std\algorithm\iteration.d(459,16):        instantiated from
here: MapResult!(__lambda2, Result)
test.d(6,69):        instantiated from here: map!(Result)
...\dmd2\src\phobos\std\algorithm\iteration.d(549,19):        instantiated from
here: __lambda2!int
...\dmd2\src\phobos\std\algorithm\iteration.d(459,16):        ... (3
instantiations, -v to show) ...
...\dmd2\src\phobos\std\algorithm\iteration.d(459,16):        instantiated from
here: MapResult!(__lambda2, Result)
test.d(6,23):        instantiated from here: map!(Result)

--
Jul 26 2015