internal compiler error with immutable

Danny via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Feb 8 05:21:28 PST 2015


Hi Ketmar,
Hi Ali,

thank you!

>On Sunday, 8 February 2015 at 09:42:14 UTC, Ali Çehreli wrote:
>     spawn(&user, cucs, ubyte(3));
^^^^^^^^^^^^^^^^^^^^^^^^^to!

Other than that, it works.

(The Attributes are basically literal constants but the library 
cannot know which are used in a given program - but probably not 
more than 20 or so are used realistically - it would be a UI 
design faux pas for content to be - like XP start menu - in 
hundreds of different yellowish greenish colors)

Unfortunately, I can't seem to get opEquals to work with 
immutable (or const, for that matter) either. (does compile, 
though)

The obvious
     bool opEquals(immutable(C) b) immutable {
         return value == b.value;
     }
doesn't work. Probably have to override the one from Object ? 
Even though I don't really use polymorphism here.

     override bool opEquals(Object b) immutable {
         return value == (cast(immutable(C)) b).value;
     }

Nope. Doesn't work (or compile) either.

As a test, I added

    foreach (ubyte i; 0 .. 10) {
         if (i % 2) {
             cucs.add(new immutable(C)(i));
             assert(new immutable(C)(i) == new immutable(C)(i)); 
// this
         }
     }

to your program but the assertion fails after the changes (if it 
even compiles).

Hmm, maybe I should just store immutable struct C pointers? Yep, 
that works, although then I have to compare for equality by *a == 
*b... oh well, I use opEquals comparison only internally after 
all.


More information about the Digitalmars-d-learn mailing list