www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5207] New: Immutability is broken in module constructor

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5207

           Summary: Immutability is broken in module constructor
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid, diagnostic
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bugzilla kyllingen.net


--- Comment #0 from Lars T. Kyllingstad <bugzilla kyllingen.net> 2010-11-12
07:23:03 PST ---
Example:

    immutable int i;

    static this()
    {
        assert (i == 0);
        i = 1;
        assert (i == 1);
    }

The compiler should give a "variable not initialised" error on the first
assert.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 12 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5207


Lars T. Kyllingstad <bugzilla kyllingen.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Immutability is broken in   |Immutability is broken in
                   |module constructor          |constructors


--- Comment #1 from Lars T. Kyllingstad <bugzilla kyllingen.net> 2010-11-12
08:24:54 PST ---
This actually holds for all constructors, not just module constructors:

    struct S
    {
        immutable int i;

        this(int k)
        {
            assert (i == 0);
            i = k;
            assert (i == k);
        }
    }

    void main()
    {
        auto s = S(1);
    }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 12 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5207


hsteoh quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh quickfur.ath.cx


--- Comment #2 from hsteoh quickfur.ath.cx 2013-07-01 12:05:00 PDT ---
Isn't this by design? In my understanding, ctors allow you to assign once, and
thereafter further assignment is prohibited. Otherwise, you couldn't have
runtime-initialized immutables, such as AA's.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 01 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5207



--- Comment #3 from Lars T. Kyllingstad <bugzilla kyllingen.net> 2013-07-02
02:01:08 PDT ---
I'm not suggesting that the assignment be prohibited.  Rather, I think it
should be illegal to *access* the variable before it is initialised.

If the current behaviour is by design, consider this an enhancement request.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 02 2013