diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index e7e701a1dd..b830bca714 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -954,7 +954,7 @@ fn (c mut Checker) stmt(node ast.Stmt) { value_type := c.table.value_type(typ) if value_type == table.void_type { typ_sym := c.table.get_type_symbol(typ) - c.error('for in: cannot index `$typ_sym.name`', it.pos) + c.error('for in: cannot index `$typ_sym.name`', expr_pos(it.cond)) } it.cond_type = typ it.kind = sym.kind diff --git a/vlib/v/checker/tests/inout/for-in-index-type.out b/vlib/v/checker/tests/inout/for-in-index-type.out new file mode 100644 index 0000000000..34e2d31fb5 --- /dev/null +++ b/vlib/v/checker/tests/inout/for-in-index-type.out @@ -0,0 +1,6 @@ +vlib/v/checker/tests/inout/for-in-index-type.v:2:11: error: for in: cannot index `int` + 1| fn main() { + 2| for a in 52 { + ~~ + 3| println(a) + 4| } \ No newline at end of file diff --git a/vlib/v/checker/tests/inout/for-in-index-type.vv b/vlib/v/checker/tests/inout/for-in-index-type.vv new file mode 100644 index 0000000000..cbc26ae11b --- /dev/null +++ b/vlib/v/checker/tests/inout/for-in-index-type.vv @@ -0,0 +1,5 @@ +fn main() { + for a in 52 { + println(a) + } +} \ No newline at end of file