Bug 9154 – Incorrectly generated assignment operator

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-12-13T19:53:00Z
Last change time
2012-12-26T14:27:21Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
andrei

Comments

Comment #0 by andrei — 2012-12-13T19:53:51Z
Comment #1 by andrei — 2012-12-13T19:57:18Z
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.
Comment #3 by k.hara.pg — 2012-12-13T21:04:27Z
Comment #4 by k.hara.pg — 2012-12-26T06:48:07Z
This is a regression caused by fixing bug 4424 in 2.061head.
Comment #5 by github-bugzilla — 2012-12-26T14:23:26Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/fefb45212291c7fbe72cb30501a3edb4caf047e2 fix Issue 9154 - Incorrectly generated assignment operator https://github.com/D-Programming-Language/dmd/commit/6c7fa392f60af6319a5979b98d42c89f0b1adde4 Merge pull request #1375 from 9rnsr/fix9154 Issue 9154 - Incorrectly generated assignment operator