Bug 13904 – calls to mutable methods are just ignored when instance is an enum
Status
RESOLVED
Resolution
INVALID
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2014-12-28T11:44:00Z
Last change time
2017-05-11T23:40:43Z
Assigned to
nobody
Creator
kanael
Comments
Comment #0 by kanael — 2014-12-28T11:44:25Z
the following code compiles and runs, and prints '10' twice.
I expect it not to compile, since x is an enum.
If x is declared as 'immutable S', it does not compile.
import std.stdio;
struct S {
uint value;
void setValue(uint v) {
value = v;
}
}
int main() {
enum S x = S(10);
writeln(x);
x.setValue(20);
writeln(x);
return 0;
}
Comment #1 by andrej.mitrovich — 2014-12-31T17:24:03Z
*** Issue 13905 has been marked as a duplicate of this issue. ***
Comment #2 by bugzilla — 2017-05-11T23:40:43Z
This is actually not a bug.
enum S x = S(10);
x.setValue(20);
is rewritten to be:
S(10).setValue(20);
which is then rewritten to be:
auto tmp = S(10);
tmp.setValue(20);
which works as expected.