internal compiler error with immutable
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Feb 8 01:09:14 PST 2015
On 02/07/2015 06:35 AM, Danny wrote:
> I'm trying to use immutable class instances and that seems to be really
> difficult.
You are not alone. :)
Just some reminders:
- immutable is a requirement that may not be usable with every type.
- immutable string foo() {} is a member function that works on immutable
objects. For that reason, that 'immutable' is recommended to appear
after the parameter list:
string foo() immutable {}
> For example, with the following program I get an internal compiler error:
It generates regular compilation errors with dmd git head.
> override immutable string toString() {
I received the following error for the toString() function above as
there is no 'Object.toString immutable' to override:
Error: function deneme.Attrsp.toString does not override any
function, did you mean to override 'object.Object.toString'?
> for(i = 0U; i < MAX_COMPRESSED_ATTRS; ++i) {
> if(codes[i] is null) {
I received the followin compilation error for the line above:
Error: non-shared inout method
std.typecons.Rebindable!(immutable(Attrsp)).Rebindable.RebindableCommon!(immutable(Attrsp),
Attrsp, Rebindable!(immutable(Attrsp))).get is not callable using a
shared mutable object
> I'm not even trying to modify the contents of the instance, I'm
> just trying to assign another one to the array slot
That would be a violation of immutable, no?
> (actually not even another one - it was null before).
The compiler does not keep track of variables to see that it is null.
Since immutable (and const) are transitive, it does not allow rebinding
a class reference.
Ali
More information about the Digitalmars-d-learn
mailing list