May 24, 2006
http://d.puremagic.com/bugzilla/show_bug.cgi?id=155

           Summary: Nested classes can't return delegates to their parents.
           Product: D
           Version: 0.157
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: sky@quit-clan.de


The following code is expected to print "Hello", but it fails to do so. This behavior seems independant from any compiler flags.
-------------------------------------------

module nestedclass;

private import std.stdio;

class Foo
{
    class Bar
    {
        void delegate() getDelegate()
        {
            return &sayHello;
        }
    }
    Bar bar;

    void sayHello()
    {
        writefln("Hello");
    }

    this()
    {
        bar = new Bar();
    }
}

int main(char[][] argv)
{
    Foo foo = new Foo();
    void delegate() sayHello = foo.bar.getDelegate();
    writefln("This should print Hello:");
    sayHello();

    return 0;
}


-- 

June 01, 2006
d-bugmail@puremagic.com schrieb am 2006-05-24:
> http://d.puremagic.com/bugzilla/show_bug.cgi?id=155

> The following code is expected to print "Hello", but it fails to do so. This behavior seems independant from any compiler flags.
> -------------------------------------------
>
> module nestedclass;
>
> private import std.stdio;
>
> class Foo
> {
>     class Bar
>     {
>         void delegate() getDelegate()
>         {
>             return &sayHello;
>         }
>     }
>     Bar bar;
>
>     void sayHello()
>     {
>         writefln("Hello");
>     }
>
>     this()
>     {
>         bar = new Bar();
>     }
> }
>
> int main(char[][] argv)
> {
>     Foo foo = new Foo();
>     void delegate() sayHello = foo.bar.getDelegate();
>     writefln("This should print Hello:");
>     sayHello();
>
>     return 0;
> }

Added to DStress as http://dstress.kuehne.cn/run/d/delegate_17_A.d

Thomas