[Issue 7265] Function Literals where a keyword was omitted should be delegate even if inference.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jan 16 10:07:09 PST 2012


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



--- Comment #5 from SHOO <zan77137 at nifty.com> 2012-01-16 10:07:04 PST ---
(In reply to comment #4)
> (In reply to comment #3)
> > Everything behaves as specified in TDPL. This is not a compiler bug.
> 
> Yah, I just tested this:
> 
> import std.stdio, std.traits;
> void main()
> {
>     auto fn = { writeln("function"); };
>     static assert(isFunctionPointer!(typeof(fn)));
>     int x;
>     auto dg = { writeln("delegate because it prints ", x); };
>     static assert(isDelegate!(typeof(dg)));
> }
> 
> So the literal is properly classified as a function or delegate depending on it
> needing a frame pointer or not.
> 

Hmm...
Because it included a clear breaking change, I thought that a sample code was
wrong.

> There's one remaining question I have. I rewrote the example like this:
> 
> 
> import std.stdio, std.traits;
> 
> void main()
> {
>     auto fn = { writeln("function"); };
>     static assert(is(typeof(fn) == function));
> 
>     int x;
>     auto dg = { writeln("delegate because it prints ", x); };
>     static assert(is(typeof(dg) == delegate));
> }
> 
> The second static assert works, but the first doesn't. Why?

"fn" of the first case is a function pointer and is not a function. The code
outputs a compilation error definitely.

-----
import std.stdio, std.traits;

void main()
{
    static assert(is(typeof(main) == function)); // true, typeof(main) is
function
    static assert(is(typeof(&main) == function)); // false, typeof(&main) is
function pointer
}
-----

-- 
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