diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index db5f5cf0ae..f88e32c259 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -1278,11 +1278,12 @@ fn (mut g Gen) for_in(it ast.ForInStmt) { atmp := g.new_tmp_var() atmp_type := g.typ(it.cond_type) if !it.cond.is_lvalue() { - g.error('for in: unhandled condition `$it.cond`', it.pos) + g.write('$atmp_type *$atmp = &(($atmp_type)') + } else { + g.write('$atmp_type *$atmp = &(') } - // TODO rvalue cond - g.write('$atmp_type *$atmp = &') g.expr(it.cond) + g.writeln(')') g.writeln(';') i := if it.key_var in ['', '_'] { g.new_tmp_var() } else { it.key_var } cond_sym := g.table.get_type_symbol(it.cond_type) diff --git a/vlib/v/tests/fixed_array_test.v b/vlib/v/tests/fixed_array_test.v index 30fa1fe83f..0c58b007ef 100644 --- a/vlib/v/tests/fixed_array_test.v +++ b/vlib/v/tests/fixed_array_test.v @@ -68,3 +68,20 @@ fn test_fixed_array_can_be_passed_as_mut_arg() { change_first_element(mut arr2) assert arr2 == [[0,2,3]!, [4,5,6]!, [7,8,9]!]! } + +fn test_iteration_over_fixed_array() { + mut s := u16(0) + arr := [u16(3), 2, 17, 23]! + for v in arr { + s += v + } + assert s == 45 +} + +fn test_iteration_over_fixed_array_literal() { + mut s := 0.0 + for v in [0.5, -2.25, 3.75, 12.0, 13.25]! { + s += v + } + assert s == 27.25 +}