Thread overview
[Issue 4664] New: Lambdas default arguments problems
Aug 17, 2010
Jonathan M Davis
Aug 17, 2010
nfxjfg@gmail.com
Aug 18, 2010
Jonathan M Davis
Aug 30, 2010
Andrej Mitrovic
Jun 08, 2011
yebblies
August 17, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4664

           Summary: Lambdas default arguments problems
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: bearophile_hugs@eml.cc


--- Comment #0 from bearophile_hugs@eml.cc 2010-08-17 07:15:28 PDT ---
In C++0x default arguments are not allowed in lambdas. In D2 they are allowed, but this program shows (compiled with dmd 2.048) that they have problems:


import std.stdio: writeln;
void foo(T)(T callme) {
    callme();
}
void main() {
    auto lam1 = (int x=5){ writeln(x); };
    auto lam2 = (int x=10){ writeln(x); };
    foo(lam1);
    foo(lam2);
}



Output:
5
5


Is it positive to disallow default arguments in D2 lambdas too?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 17, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4664


Jonathan M Davis <jmdavisProg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg@gmail.com


--- Comment #1 from Jonathan M Davis <jmdavisProg@gmail.com> 2010-08-17 16:42:10 PDT ---
I would think that it would be better if the two didn't conflict as opposed to getting rid of default parameters. It looks like they're being turned into the same function when they're not (at least conceptually) - one because they have different default parameters, and two because they're lambdas, not functions with names.

Now, assuming that it can't be fixed so that these functions are actually separate like you'd think that they'd be, then it would probably be better to disallow default arguments, but I'd argument that this is a compiler bug rather than a bug in the language.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 17, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4664


nfxjfg@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nfxjfg@gmail.com


--- Comment #2 from nfxjfg@gmail.com 2010-08-17 16:59:15 PDT ---
Is this a dupe of bug #4028?
Short story: dmd merges the two delegate types into one, and the first default
value "wins".

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 18, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4664



--- Comment #3 from Jonathan M Davis <jmdavisProg@gmail.com> 2010-08-17 19:12:50 PDT ---
It does look like it's essentially a duplicate, though the way that the problem is hit is a bit different.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 30, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4664


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich@gmail.com


--- Comment #4 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2010-08-30 06:35:48 PDT ---
As a quick hack while this isn't fixed you can use this:

    auto lam1 = function (int x=5){ writeln(x); };
    auto lam2 = delegate (int x=10){ writeln(x); };

But this will only work with 2 lambdas at most, and it isn't very nice. :)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 08, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4664


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |yebblies@gmail.com
         Resolution|                            |DUPLICATE


--- Comment #5 from yebblies <yebblies@gmail.com> 2011-06-08 07:30:12 PDT ---
*** This issue has been marked as a duplicate of issue 4028 ***

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