Closed ken0x0a closed 2 years ago
The whole test & original code is here https://github.com/vpkgs/std/blob/main/vec/vec_test.v https://github.com/vpkgs/std/blob/main/vec/vec.v
I was trying to implement an array, that I can inspect value in lldb
easily (without casting type).
This is an error due to the assert mechanism, assert calls the left and right expression repeatedly. The following is ok:
fn main() {
mut arr := with_cap<int>(5)
for i in 0 .. 5 {
arr.push(i)
}
for g in arr.iter() {
dump(*g)
}
mut iter := arr.iter()
r1 := *(iter.next()?)
assert r1 == 0
r2 := *(iter.next()?)
assert r2 == 1
r3 := *(iter.next()?)
assert r3 == 2
r4 := *(iter.next()?)
assert r4 == 3
r5 := *(iter.next()?)
assert r5 == 4
if _ := iter.next() {
assert false
}
}
I understand that the generated C code has multiple next
call for *(...)
.
for *(iter.next()?)
_option_int_ptr _t3 = main__Iter_T_int_next_T_int(&iter);
if (_t3.state != 0) {
main__TestRunner_name_table[test_runner._typ]._method_fn_error(test_runner._object, 58, tos3("unexpected_value_vec_test.v"), tos3("main"), tos3("test_vec_iter"), IError_name_table[_t3.err._typ]._method_msg(_t3.err._object) );
longjmp(g_jump_buffer, 1);
}
_option_int_ptr _t5 = main__Iter_T_int_next_T_int(&iter);
if (_t5.state != 0) {
main__TestRunner_name_table[test_runner._typ]._method_fn_error(test_runner._object, 58, tos3("unexpected_value_vec_test.v"), tos3("main"), tos3("test_vec_iter"), IError_name_table[_t5.err._typ]._method_msg(_t5.err._object) );
longjmp(g_jump_buffer, 1);
}
_option_int_ptr _t7 = main__Iter_T_int_next_T_int(&iter);
if (_t7.state != 0) {
main__TestRunner_name_table[test_runner._typ]._method_fn_error(test_runner._object, 58, tos3("unexpected_value_vec_test.v"), tos3("main"), tos3("test_vec_iter"), IError_name_table[_t7.err._typ]._method_msg(_t7.err._object) );
longjmp(g_jump_buffer, 1);
}
for iter.next()?
_option_int_ptr _t9 = main__Iter_T_int_next_T_int(&iter);
if (_t9.state != 0) {
main__TestRunner_name_table[test_runner._typ]._method_fn_error(test_runner._object, 59, tos3("unexpected_value_vec_test.v"), tos3("main"), tos3("test_vec_iter"), IError_name_table[_t9.err._typ]._method_msg(_t9.err._object) );
longjmp(g_jump_buffer, 1);
}
But I don't know why assert
act like this.
I'm closing this, as this behavior is intentional(?).
Please reopen, if it's not intentional.
V version: V 0.3.1 d7758b2.69c9d47 OS: macos, macOS, 12.6, 21G115
What did you do?
What did you expect to see? pass test
What did you see instead?