[Issue 15839] this.outer is of wrong type

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Mar 31 01:28:56 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=15839

--- Comment #7 from Jacob Carlborg <doob at me.com> ---
I tried modifying my code to explicitly pass in the outer this reference. That
works until you have nested anonymous classes. For example:

interface A {}
interface B {}

class Foo
{
    void foo()
    {
        auto a = new class(this) A {
            Foo outer;
            this(Foo outer)
            {
                this.outer = outer;
                this.outer.bar();

                auto b = new class(this) B {
                    A outer;
                    this(A outer)
                    {
                        this.outer = outer;
                        this.outer.outer.bar(); // line 20
                    }
                };
            }
        };
    }

    void bar() {}
}

The above will of course fail to compile since there's no "bar" in "A":

main.d(20): Error: no property 'outer' for type 'main.A'

Any suggestions?

--


More information about the Digitalmars-d-bugs mailing list