On Thu, 26 Apr 2012 09:08:07 -0400, Steven Schveighoffer
<[email protected]> wrote:
void main()
{
auto a = (int x = 1) { return x;};
pure nothrow @safe int function(int) b = (int x) { return x;};
pragma(msg, typeof(a).stringof);
pragma(msg, typeof(b).stringof);
b = a; // ok
//a = b; // error
//b(); // error
}
output:
int function(int x = 1) pure nothrow @safe
int function(int)
Nevermind, I just realized it was ignoring my pure nothrow @safe for the
declaration. Moving it after the declaration results in:
void main()
{
auto a = (int x = 1) { return x;};
int function(int) pure nothrow @safe b = (int x) { return x;};
pragma(msg, typeof(a).stringof);
pragma(msg, typeof(b).stringof);
}
output:
int function(int x = 1) pure nothrow @safe
int function(int x = 1) pure nothrow @safe
which clearly mimics the auto behavior. This is *really* no good, since
it seems to be ignoring the explicit type that I specified.
IMO, the correct solution is to make the default argument part of the type
(and don't let it affect things globally!), and make it derived from the
version without a default arg. I think Michel Fortin said the same thing.
-Steve