[Issue 7514] [e2ir] Error in e2ir at dynamic array to static array cast
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Thu Jan 22 08:22:49 PST 2015
https://issues.dlang.org/show_bug.cgi?id=7514
--- Comment #12 from Kenji Hara <k.hara.pg at gmail.com> ---
(In reply to bearophile_hugs from comment #11)
> (In reply to Kenji Hara from comment #10)
>
> > I think the cast from int[] to int[2][1] should not be accepted.
>
> Can you please explain why?
>
> Currently this is accepted:
> int[2] m = cast(int[2])[1, 2];
In cast(int[2])[1, 2], the array literal can *structurally* match to the type
int[2] - all elements can be implicitly convertible to int, and the array
literal contains 2 elements. Therefore the cast is accepted.
Contrary to that, in cast(int[2][1])[1, 2] compiler cannot find any structural
conversions. Therefore it will be a reinterpret cast, but dmd has no proper
codegen way for the cast from int[] to int[2][1].
That's why the former is accepted but the latter isn't.
--
More information about the Digitalmars-d-bugs
mailing list