www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - inout/const issue: assignments to field not allowed if field

reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
It took me a while to narrow this down:

struct Foo
{
    int val = int.init;
    this(inout(int) nval) inout {
        this.val = nval;
    }
}

test.d(18): Error: cannot modify const/immutable/inout expression this.val

Is there any special reason why this should be disallowed? I mean the
same thing happens if you do a void initialization: int val = void;

A bug?
Mar 10 2012
parent Timon Gehr <timon.gehr gmx.ch> writes:
On 03/11/2012 02:46 AM, Andrej Mitrovic wrote:
 It took me a while to narrow this down:

 struct Foo
 {
      int val = int.init;
      this(inout(int) nval) inout {
          this.val = nval;
      }
 }

 test.d(18): Error: cannot modify const/immutable/inout expression this.val

 Is there any special reason why this should be disallowed? I mean the
 same thing happens if you do a void initialization: int val = void;

 A bug?

That a void-initialized field cannot be initialized is certainly a bug.
Mar 11 2012