www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7955] New: Nested function error in sort with lambda template but not with a lambda

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7955

           Summary: Nested function error in sort with lambda template but
                    not with a lambda
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



import std.algorithm: sort;
int foo(int n)() {
    sort!((a, b) => true)([1]);
    //sort!((int a, int b) => true)([1]);
    foo!1();
    return 0;
}
void main() {
    foo!0();
}



DMD 2.059 shows:

...\dmd2\src\phobos\std\algorithm.d(6781): Error: function
test.foo!(0).foo.sort!(__lambda3,cast(SwapStrategy)0,int[]).sort is a nested
function and cannot be accessed from test.foo!(1).foo

The version that uses the lambda instead of a lambda template compiles
correctly (then crashes at a runtime because the sort function is stupid).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 20 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7955


Denis <verylonglogin.reg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |verylonglogin.reg gmail.com



---
Reduced testcase:
---
void f(alias fun)() { }

void g(T)() {
    f!(a => a)();
}

void main() {
    g!int();
    g!long();
}
---
Error: function main.g!(int).g.f!(__lambda2).f is a nested function and cannot
be accessed from main.g!(long).g

Workaround: explicitly define lambda type: `(int a) => a`.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 03 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7955


Denis Shelomovskij <verylonglogin.reg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WORKSFORME



11:16:19 MSD ---
Like Issue 7917 it compiles fine now. Then crashes at a runtime because of
infinite recursion. Please open a new issue is there is a problem with `sort`.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 04 2013