On Mon, 31 Mar 2014 14:58:30 -0400, anonymous <n...@trash-mail.com> wrote:

Hi,
I'm new to D and played a bit with templates and delegates.
Now i discovered some behaviore that i don't understand.
Can somebody explain me why i get two different outputs?


import std.stdio;


interface A(T){
        bool GetBool();
        T getT();
}

class C:A!(double){
        override bool GetBool(){
                return false;
        }
        override double getT(){
                return 1;
        }
}

void mwriteln(T)( A!T delegate() dg){
        writeln(dg().getT());
}

void main()
{
        auto c = new C();
        writeln(c.getT());
        mwriteln!double({return new C();});
}

This is definitely a bug.

Reduced case:

import std.stdio;

interface A{
    void foo();
}

class C:A{
    override void foo(){
        writeln("here");
    }
}

void x( A delegate() dg){
    dg().foo();
}

void main()
{
    A c = new C;
    c.foo(); // prints "here"
    x({A a = new C; return a;}); // prints "here"
    x({return new C;}); // does not print
}

This is really an issue with delegate return type inferrence not working properly.

-Steve

Reply via email to