www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10496] New: Initialization in lazy function parameter allows immutable member not to be initialized

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

           Summary: Initialization in lazy function parameter allows
                    immutable member not to be initialized
           Product: D
           Version: D1 & D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: david.eckardt sociomantic.com



09:00:44 PDT ---
class C
{
    immutable int x;

    this()
    {
        this.f(this.x = 5);
    }

    void f(lazy int x){}
}

C.int isn't initialized, although this code compiles.
Whether C.int is initialized or not depends on the, in general indeterministic,
behavior of f(), this should be a compile time error.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 28 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10496


Dicebot <m.strashun gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |m.strashun gmail.com



I think this is part of a bigger problem:

----------------------------------------
class A
{
    immutable int x;

    void delegate() f;

    this()
    {
        x = 40;
        f = () { x = 42; };
    }
}

void main()
{
    import std.stdio;
    auto a = new A();
    writeln(a.x);
    a.f();
    writeln(a.x);
}
----------------------------------------

40
42

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


Maxim Fomin <maxim maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim maxim-fomin.ru



---
The root is that delegate construction does not respect immutability at all.

struct S
{
   void foo() immutable {}
   void baz() 
   {
      //foo();
      (&foo)();
   }
}

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