Immutable static arrays

Daniel Murphy yebblies at nospamgmail.com
Fri Mar 16 21:03:02 PDT 2012


"H. S. Teoh" <hsteoh at quickfur.ath.cx> wrote in message 
news:mailman.804.1331956668.4860.digitalmars-d at puremagic.com...
> On Fri, Mar 16, 2012 at 08:53:06PM -0700, H. S. Teoh wrote:
> [...]
>> More to the point, how should AA's with immutable static array keys be
>> implemented? The current implementation doesn't work at all because the
>> input static array can't be assigned to the Slot (the static array field
>> in Slot is completely immutable, even from the Slot ctor???).
>
> P.S. The error message is:
>
> newAA.d(58): Error: slice this.key[] is not mutable
>
> which is odd, because the code reads:
>
>    struct Slot
>    {
>        Slot   *next;
>        hash_t  hash;
>        Key     key;
>        Value   value;
>
>        this(K)(hash_t h, K k, Value v, Slot *_next=null) if (keyCompat!K)
> {
> static if (is(K : Key))
> key = k; // line 58
> else ...
> }
> ...
>    }
>
> (This is being instantiated with Key == immutable char[4]).
>
> Why is the assignment being translated into a slice for the assignment?
>
>
> T
>
> -- 
> Nobody is perfect.  I am Nobody. -- pepoluan, GKC forum

Oh, this.  There are a bunch of bugs with const/immutable static arrays. 
During AssignExp::semantic, a = b (where a and b are static arrays) gets 
converted to a[] = b[].  This is incorrect, the transformation should happen 
during the glue layer. 




More information about the Digitalmars-d mailing list