make •bit._cast properly error on non-array 𝕩

This commit is contained in:
dzaima 2022-03-06 13:44:27 +02:00
parent 2ac2309ed8
commit 03978f333c

View File

@ -984,10 +984,11 @@ static u8 typeOfCast(CastType t) {
} }
} }
B bitcast_impl(B el0, B el1, B x) { B bitcast_impl(B el0, B el1, B x) {
CastType xt = getCastType(el0, x);
CastType zt = getCastType(el1, bi_N);
ur xr; ur xr;
if (!isArr(x) || (xr=rnk(x))<1) thrM("•bit._cast: 𝕩 must have rank at least 1"); if (!isArr(x) || (xr=rnk(x))<1) thrM("•bit._cast: 𝕩 must have rank at least 1");
CastType xt = getCastType(el0, x);
CastType zt = getCastType(el1, bi_N);
usz* sh = a(x)->sh; usz* sh = a(x)->sh;
usz s=xt.s*sh[xr-1], zl=s/zt.s; usz s=xt.s*sh[xr-1], zl=s/zt.s;
if (zl*zt.s != s) thrM("•bit._cast: incompatible lengths"); if (zl*zt.s != s) thrM("•bit._cast: incompatible lengths");