Tested with DMD 2.066, commit 497b168d1acf28a809f71efa4d7cac908a6d8b7f
//
struct A{ short a; }
struct B{ ubyte b; }
enum call = (){
A[] a = [ A(1), A(2)];
B[] b = [ B(3), B(4)];
void[] pa = a[];
void[] pb = b[];
pa[] = pb[]; // length mismatch is silently ignored at CTFE?
pa[0..2] = pb[]; //
static assert(is(typeof(a[0]) == A)); /passes
return a[0];
};
enum x = call();
pragma(msg, typeof(x)); //prints A
pragma(msg, x); //prints B(cast(ubyte)3)
void main()
{
auto y = call();
assert(y == x);
}
Comment #1 by n8sh.secondary — 2021-03-18T07:19:57Z
As of 2.072 this code does not compile in `@safe`: "Error: cannot copy void[] to void[] in @safe code." The interesting CTFE behavior still occurs as of 2.096.
Comment #2 by robert.schadek — 2024-12-13T18:19:46Z