[Issue 4312] std.traits.ReturnType no longer accepts function literals
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri May 27 07:20:47 PDT 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4312
--- Comment #6 from kennytm at gmail.com 2011-05-27 07:16:28 PDT ---
(In reply to comment #5)
> I'm not defining a closure. I'm defining a nested function literal. And given
> that the following compiles:
>
> void main()
> {
> int b;
> int funcliteral(int a){return a+b;}
> writeln( (ReturnType!funcliteral).stringof );
> }
>
That's because the '&' of that 'funcliteral' is a delegate. Try it:
---------------------------------
void main() {
void f() {};
static void g() {};
pragma(msg, typeof(&f)); // void delegate()
pragma(msg, typeof(&g)); // void function()
}
---------------------------------
And the following also does not compile:
---------------------------------
void main() {
int b;
static int func(int a) { return a+b; }
}
---------------------------------
x.d(6): Error: function x.main.func cannot access frame of function D main
---------------------------------
See http://d-programming-language.org/expression.html#FunctionLiteral.
> I would also expect
>
> void main(string[] args) {
> int b;
> writeln( (ReturnType!( function(int a){return a+b;} )).stringof );
> }
>
> to work. But, as you pointed out, this isn't a problem with ReturnType anymore.
--
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