www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8402] New: Lambda argument's default value is not taken into account

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

           Summary: Lambda argument's default value is not taken into
                    account
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: kolos80 bk.ru


--- Comment #0 from Artem Borisovskiy <kolos80 bk.ru> 2012-07-20 05:33:24 PDT
---
The following code does not compile (x.d):

void main()
{
    auto fn = (int x = 0) => x + 1;
    fn();
}

with message: "x.d(4): Error: expected 1 function arguments, not 0"
However, calling fn() with an explicit argument works fine as usual.

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


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg gmx.com


--- Comment #1 from Jonathan M Davis <jmdavisProg gmx.com> 2012-07-20 10:27:41
PDT ---
Default arguments with lambda functions don't really make sense given that
they're generally only used in one place, that default arguments are _not_ part
of the type (they're just inserted at the call site), and that there's no way
for lambdas or function pointers to carry default arguments with them. So, the
fact that it doesn't compile is a _good_ thing, though it really should give an
error for giving a default argument and not just an error at the call site.

This is related to bug# 3646, but I'm not sure if it's strictly speaking a
duplicate or not.

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


Erik Johansson Andersson <exetoc gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |exetoc gmail.com


--- Comment #2 from Erik Johansson Andersson <exetoc gmail.com> 2012-08-02
14:27:43 PDT ---
This seems to be relevant:

void function(int i = 0) f = (int i){};
void delegate(int i = 0) g = (int i){};

void main()
{   
    f();
    g();
}

The error message is: "Error expected 1 function arguments, not 0", for both f
and g.

(In reply to comment #1)
 Default arguments with lambda functions don't really make sense given that
 they're generally only used in one place, that default arguments are _not_ part
 of the type (they're just inserted at the call site), and that there's no way
 for lambdas or function pointers to carry default arguments with them. So, the
 fact that it doesn't compile is a _good_ thing, though it really should give an
 error for giving a default argument and not just an error at the call site.
 
 This is related to bug# 3646, but I'm not sure if it's strictly speaking a
 duplicate or not.
It did work in 2.059, which was nice, because it allowed libraries like Derelict to provide bindings for C++ libraries like FreeImage, without having to modify the interface in order to take into account potential default arguments which, as of 2.060, isn't the case anymore. Did this old behaviour have any negative effects at all? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 02 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8402


timon.gehr gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |timon.gehr gmx.ch


--- Comment #3 from timon.gehr gmx.ch 2012-08-02 17:36:56 PDT ---
(In reply to comment #2)
 Did this old behaviour have any negative effects at all?
Probably the feature was there by mistake. It was implemented incorrectly. I think just associating the default arguments with the variable declaration might work if something like it should be supported. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 02 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8402



--- Comment #4 from Erik Johansson Andersson <exetoc gmail.com> 2012-08-02
20:04:56 PDT ---
I was referring to variables (and not literals) in the latter part of my
comment, whereas you probably didn't. If that is indeed the case, then
disregard what I said.

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



--- Comment #5 from Kenji Hara <k.hara.pg gmail.com> 2012-08-04 10:11:15 PDT ---
(In reply to comment #0)
 The following code does not compile (x.d):
 
 void main()
 {
     auto fn = (int x = 0) => x + 1;
     fn();
 }
 
 with message: "x.d(4): Error: expected 1 function arguments, not 0"
 However, calling fn() with an explicit argument works fine as usual.
The function pointer `fn` is not a lambda itself, so cannot have default argument. If it is allowed: auto fn = (int x = 0) => x + 1; fn(); // returns 1 fn = (int x = 1) => x + 1; fn(); // returns 1 or 2? What is returned by the 2nd call of fn? I cannot imagine it. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 04 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8402


Kenji Hara <k.hara.pg gmail.com> changed:

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


--- Comment #6 from Kenji Hara <k.hara.pg gmail.com> 2012-08-04 10:12:29 PDT ---
This issue is a part of bug 3866.

*** This issue has been marked as a duplicate of issue 3866 ***

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