www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Bug 155] New: Nested classes can't return delegates to their parents.

reply d-bugmail puremagic.com writes:
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;
}


-- 
May 24 2006
parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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 -----BEGIN PGP SIGNATURE----- iD8DBQFEft6Z3w+/yD4P9tIRAhcTAKDHESG/KoYSou4c8XsP9a8QnJClngCgputO a1U7irqjK5ys12Q0nSDQiNk= =obR2 -----END PGP SIGNATURE-----
Jun 01 2006