Bug 14343 – Postfix increment doesn't work on structs with immutable member
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-03-26T09:05:00Z
Last change time
2015-06-17T21:03:15Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
dransic
Comments
Comment #0 by dransic — 2015-03-26T09:05:25Z
struct S
{
int i;
immutable(Object) o;
S opUnary(string op)() { return this; }
void opAssign(S other) {}
}
void main()
{
S s, t;
t = s; // OK
++s; // OK
s++; // Error: cannot modify struct s S with immutable members
}
Comment #1 by dransic — 2015-03-26T09:07:22Z
The problem doesn't show with the old operator overloading methods:
struct S
{
int i;
immutable(Object) o;
void opAddAssign(int j) { i += j; }
S opPostInc() { ++i; return this; }
void opAssign(S other) {}
}
unittest
{
S s;
++s;
assert(s.i == 1);
s++;
assert(s.i == 2);
}