Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect initialization of nested classes #18934

Open
dlangBugzillaToGithub opened this issue Jan 22, 2015 · 0 comments
Open

Incorrect initialization of nested classes #18934

dlangBugzillaToGithub opened this issue Jan 22, 2015 · 0 comments

Comments

@dlangBugzillaToGithub
Copy link

mfx reported this on 2015-01-22T19:16:24Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=14030

Description

It seems that "outer" is not correctly set for nested classes
when using static const objects.

Please see "NULL" in the code below.

// dmd 2.066.1

class Outer {
    size_t x = 1;
    final class Inner {
        size_t y = 2;
        auto foo() const { return x + y; }
        // <== info: here is a ref "Outer outer;"
    }
}

void main() {
    import std.stdio: writeln;

           const a = (new Outer).new Inner;
    static const b = (new Outer).new Inner;

    assert(a.foo() == 3);

    writeln((cast(size_t **)(a))[0]);   // __vptr
    writeln((cast(size_t **)(a))[1]);   // __monitor
    writeln((cast(size_t **)(a))[2]);   // y
    writeln((cast(size_t **)(a))[3]);   // outer

    writeln((cast(size_t **)(b))[0]);
    writeln((cast(size_t **)(b))[1]);
    writeln((cast(size_t **)(b))[2]);
    writeln((cast(size_t **)(b))[3]);   // => NULL !

    assert(b.foo() == 3);               // runtime crash here

    // enable this for error message:
    //   Error: class 'this.this' is null and cannot be dereferenced
    static if (0) {
        static assert(b.foo() == 3);
    }
}

// EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant