[Issue 19928] New: disallow modification of immutable in constructor after calling base ctor

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri May 31 14:38:23 UTC 2019


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

          Issue ID: 19928
           Summary: disallow modification of immutable in constructor
                    after calling base ctor
           Product: D
           Version: D2
          Hardware: x86
                OS: Mac OS X
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: schveiguy at yahoo.com

This breaks immutability:

import std.stdio;
class C
{
    void foo() { writeln("C");}
    this()
    {
        foo();
    }
}

class D : C
{
    immutable int x;
    this()
    {
        super();
        x = 5;
        foo();
    }
    override void foo()
    {
        writeln("D: ", x);
    }
}

void main()
{
    new D;
}

x could be considered final once any base ctor is called, or really any
function which accepts a path back to x (like if you call some external
bar(this), it should be the same thing).

--


More information about the Digitalmars-d-bugs mailing list