Based on a newsgroup post by Tomek SowiƱski. Both these testcases compile without error:
----------
import std.stdio;
const int a;
void foo(ref int i) {
i = 4;
}
void foo() {
foo(a);
}
void main() {
writefln("%d", a);
foo();
writefln("%d", a);
}
----------
The bug disappears if a is explicitly initialised.
----------
import std.stdio;
const int value;
void changeConst() {
doChange(value);
}
void doChange(ref int var) {
var = 42;
}
void main() {
writefln("%d", value);
changeConst();
writefln("%d", value);
}
----------
The bug disappears if a is explicitly initialised.
----------
import std.stdio;
class Class {
int value;
void changeConst() const {
doChange(value);
}
void doChange(ref int var) const {
var = 42;
}
}
void main() {
Class obj = new Class;
writefln("%d", obj.value);
obj.changeConst();
writefln("%d", obj.value);
}
----------
The bug also bits if doChange is made static or global and the const attribute removed. If only the const attribute is removed, the error is correctly diagnosed (though this may be partly due to another bug).
Comment #1 by smjg — 2010-09-17T05:17:43Z
*** Issue 4877 has been marked as a duplicate of this issue. ***
Comment #2 by yebblies — 2011-01-26T18:27:29Z
*** This issue has been marked as a duplicate of issue 5493 ***