[Issue 3866] anonymous delegate with default parameters cross-talks to another anonymous delegate

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Apr 26 10:32:15 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=3866


Jonathan M Davis <jmdavisProg at gmx.com> changed:

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


--- Comment #4 from Jonathan M Davis <jmdavisProg at gmx.com> 2012-04-26 10:33:19 PDT ---
It was my understanding that default arguments were just arguments that were
inserted when a function was called and you didn't provide all of the
arguments. They aren't actually part of the signature or type at all. As such,
they are only known if you call the function directly. If you use a function
pointer (or delegate), then all you have is the signature, so you don't have
any default arguments. As such, nested functions with default arguments such as

static auto foo(int a = 1)
{
    return a;
}

and

auto foo(int a = 1)
{
    return a + b;
}

should work just fine, but as with any function, as soon as you take their
address or turn them into a delegate variable, their default arguments are
lost. And so having default arguments in something like

auto foo = (int a = 1) { return a;};
auto bar = (int a) { return a;};

is completely pointless, because all you have is a variable which knows the
signature of the function/delegate to call. The function itself can't be called
directly, so it doesn't have any default arguments associated with it, and so
there's no point in the default arguments even being legal.

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


More information about the Digitalmars-d-bugs mailing list