Might have two separate issues here. I commented some peculiarities I found while playing around with the code.
Issue description:
Seems like adding an external function messes up the code generation, when arrays of functions are assigned. This also happens for arrays of structs that contain functions.
Issues:
-
It seems like only the last function that was written to (in an array of functions) can be accessed, when using an external function in the loop.
-
We also can't use range(...) to write to the function array. We need to use unroll(...).
The following code will not compile in the current configuration:
#[import] fn extern_fun(&u8) -> ();
#[export]
fn @main() -> i32 {
let dummy_u8_ref:&u8;
let mut test_arr:[fn()->i32 * 3]; // <- set this to 2 (since we are using 1 in test_arr(1)()) and it will compile. It seems like the last function
let iterations = 3; // <- or set this to 2 written to can be accessed, every other function can't.
for i in unroll(0, iterations){ // Changing this to "range" will result in no compilation even when excluding "extern_fun".
extern_fun(dummy_u8_ref); // Without this it will compile just fine. (When using unroll).
test_arr(i) = @||{i}; // Without this it will not compile (no matter where the array is accessed).
}
test_arr(1)() // Set this to 2 and it will compile. (0 also won't work). Without this line it will compile just fine. (With range or unroll).
}