Consider:
struct S {
int x;
void opAssign(ref S s) { }
}
struct T {
S member;
}
void main() {
T t1, t2;
t1 = t2;
}
This fails to compile with the error:
Error: cannot modify struct t1 T with immutable members
The error is caused by the "ref" in the definition of opAssign. Replacing "ref" with "ref const" or "ref immutable" doesn't help, either.
The compiler should act mechanically here: the generated assignment for T should simply perform a field-by-field assignment without nitpicking.
Comment #2 by k.hara.pg — 2012-12-13T21:02:05Z
(In reply to comment #1)
> The compiler should act mechanically here: the generated assignment for T
> should simply perform a field-by-field assignment without nitpicking.
OK. When I organized "identity assignable" concept, I had lacked it in my fix (mainly dmd pull #166).
- Even if user defines an opAssign which receives only lvalue, compiler should treat it as identity opAssign.
This is satisfied the condition for field-by-field assignment.
Then, S is treated as an "identity assignable" struct, and built-in opAssign generating in T will succeed correctly.