[Issue 13775] [REG2.067a] Broken explicit casting of dynamic array slices of known size to static array of different type

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Feb 15 18:42:14 PST 2015


https://issues.dlang.org/show_bug.cgi?id=13775

Kenji Hara <k.hara.pg at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #20 from Kenji Hara <k.hara.pg at gmail.com> ---
(In reply to Martin Nowak from comment #19)
> (In reply to Kenji Hara from comment #18)
> > Read my comment #9. It was *accidentally* accepted in 2.066.1.
> 
> This code used to work even with 2.065.
> Maybe the difference here is that it's a slice of a static array?
> 
> void bar(ubyte[2] v)
> {
> }
> 
> void foo(ubyte[16] ip)
> {
>     foreach (i; 0 .. 8)
>         bar(cast(ubyte[2])ip[i*2 .. i*2+2]);
> }

No, it's same. Issue 3652 has been implemented since 2.063, so the
accepts-invalid bug was also introduced from 2.063.

With 2.062, the code reports e2ir error.

test.d(8): Error: e2ir: cannot cast ip[cast(uint)(i * 2)..cast(uint)(i * 2 +
2)] of type ubyte[] to type ubyte[2u]
Internal error: e2ir.c 85

In 2.067a, it has been fixed back to an invalid cast.
As a note, currently most of check code for the invalid casts has been moved
into front-end layer. So the reported error message is a little different.

test.d(8): Error: cannot cast expression ip[cast(uint)(i * 2)..cast(uint)(i * 2
+ 2)] of type ubyte[] to ubyte[2]

--


More information about the Digitalmars-d-bugs mailing list