Mixed closures and class.outer references

Iain Buclaw via Digitalmars-d digitalmars-d at puremagic.com
Mon Apr 13 01:12:07 PDT 2015


On 12 April 2015 at 21:36, Iain Buclaw <ibuclaw at gdcproject.org> wrote:
> Hi,
>
> Can someone tell me what is supposed to happen in Outer.foo.Inner.bar?
>  And how it should look in debug?
>
> ---
> class Outer
> {
>     int x = 42;
>     void foo()
>     {
>         int y = 43;
>         class Inner
>         {
>             void bar()
>             {
>                 assert(x == 42);
>                 assert(y == 43);
>             }
>         }
>         Inner b = new Inner();
>         b.bar();
>     }
> }
> ---
>
> What I'm currently seeing is:
>
> Function: Inner.bar()
> Params: (this=...)
> typeof(this) == Inner
> typeof(this.this) == Outer
>
> No sign of the closure in Outer.foo, so how is 'y' even accessible?

I've raised a bug:  https://issues.dlang.org/show_bug.cgi?id=14442


More information about the Digitalmars-d mailing list