D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 14030 - Incorrect initialization of nested classes
Summary: Incorrect initialization of nested classes
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-01-22 19:16 UTC by mfx
Modified: 2024-12-13 18:39 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description mfx 2015-01-22 19:16:24 UTC
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
Comment 1 dlangBugzillaToGithub 2024-12-13 18:39:15 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18934

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB