noname
noname copied to clipboard
Support var.len
It will be handy to directly obtain the length of an array variable.
For example
fn init_arr(const LEN: Field) -> [Field; LEN + 2] {
return [0; LEN + 2];
}
fn main() {
let arr = init_arr(10);
assert_eq(arr.len, 12);
// should also support being used to instantiate functions in mast phase
let arr2 = init_arr(arr.len);
assert_eq(arr2.len, 14);
}
let me take it
I think .len() would be better, or even a len() builtin function that works on any type :D
I think
.len()would be better, or even alen()builtin function that works on any type :D
I am adding new builtin len function into BUILTIN_FN_NAMES
I am debugging now this test to find out where assert_fn_eq gets invoked, but it looks like it is not called anywhere.
#[test]
fn test_array_len() {
let code = r#"
fn main(pub xx: Field) {
let aa = xx + 1;
assert_eq(aa, xx);
}
"#;
if let Err(err) = mast_pass(code) {
println!("err: {:?}", err);
}
assert_eq!(1, 2);
}