[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 03:48:15 PST 2012


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



--- Comment #2 from SHOO <zan77137 at nifty.com> 2012-01-16 03:48:12 PST ---
(In reply to comment #1)
> This is a case of outdated documentation.
> From TDPL, p150:
> "If both function and delegate are absent from the literal, the compiler
> automatically detects which one is necessary".

It is an example unlike the specifications(TDPL, p150).

The case is the following situation:

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

void main()
{
    void function() fn = { writeln("function"); };
    static assert(isFunctionPointer!(typeof(fn)));

    void delegate() dg = { writeln("delegate"); };
    static assert(isDelegate!(typeof(dg)));
}
-------

As noted above, the specifications are applied only when there is a necessary
type.
When there is not a required type, in the case like this time, it should infer
the type of the default.

This resembles the following examples:
-------
import std.traits;

void main()
{
    byte a = 1; // typeof(a) is byte
    auto b = 1; // typeof(b) is int

    // int cannot implicitly cast to byte.
    static assert (isImplicitlyConvertible!(typeof(b), typeof(a))); // false.
}
-------

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