[Issue 2293] New: access instance members from inside delegates

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Aug 19 08:16:42 PDT 2008


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

           Summary: access instance members from inside delegates
           Product: D
           Version: 1.034
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: enzo.petrelli at fastwebnet.it


/***************************
        OS:                     Windows XP Pro SP2 / Vista SP1
        Compiler/linker:        Digital Mars D Compiler v1.034
        Tango/tangobos Lib:     tango-0.99.7-bin-win32-dmd.1.033
        Compiled with:          no compile/link flag

        in the first call of the method test of the DelegateTest class
instance,
        the delegate defined inside the inner class doesn't access correctly
the
        outer class' member miVal

        in the second call of te same method, from inside a try/catch block the
        outer class' delegate also fails to correctly access the miVal member

 ***************************/

import tango.core.Exception;
import tango.io.Stdout;

void main()
{
        DelegateTest test = new DelegateTest;
        Stdout.format("outside try/catch").newline;
        test.test();
        Stdout.newline.format("inside try/catch").newline;
        try
        {
                test.test();
        } catch (Exception)
        {
        }
}

class DelegateTest
{
        int                     miVal;
        void delegate() mpDelegate;
        InnerClass              moInn;

        this()
        {
                miVal = 5;
                moInn = new InnerClass;
                mpDelegate = {
                        Stdout.format("OuterTest.delegate  this:{} miVal:{}",
cast(void*) &this, miVal).newline;
                        };
                Stdout.format("OuterTest.ctor      this:{} miVal:{}",
cast(void*) &this, miVal).newline;
        }

        void test()
        {
                moInn.mpInnerDelegate();
                mpDelegate();
        }

        class InnerClass
        {
                void delegate() mpInnerDelegate;
                this()
                {
                        mpInnerDelegate = {
                                Stdout.format("InnerClass.delegate this:{}
miVal:{}", cast(void*) &this, miVal).newline;
                                };
                        Stdout.format("InnerClass.ctor     this:{} miVal:{}",
cast(void*) &this, miVal).newline;
                }
        }
}


-- 



More information about the Digitalmars-d-bugs mailing list