jasmin
jasmin copied to clipboard
Errors with array copies
If we copy a stack array into a reg array, we can easily get errors. It is enough to have the size of the target array (in bytes) not a multiple of the cell size of the source array.
If the target array is so small that is cannot store even one element of the source array, we have an internal compilation error.
fn f () -> reg u64 {
reg u64 res;
stack u16[1] a;
reg u256[10] b;
a = b;
res = (64u)a[0];
return res;
}
// internal compilation error in function f:
// array copy: bad type for copy
If the target array can store at least one element of the source array, we have a type error.
fn f () -> reg u64 {
reg u64 res;
stack u16[33] a;
reg u256[10] b;
a = b;
res = (64u)a[0];
return res;
}
// typing error: the left value a has type u16[33] while u8[64] is expected
The error message is not perfect, because it suggests a good size, but there are other solutions (e.g. u16[16], and even u16[48] if we consider also larger arrays).
Is this still valid? I'll give a try tomorrow.
The internal compilation error has been fixed in 2022.04.0.
Indeed, the internal compilation error is not there any more. But I must admit I don't get what the rules now are (in what cases the copy can be inserted, in what cases it's not possible and we should get a type error). I tried some variations for the types of a and b and don't really understand the error messages I receive, but I won't investigate more.