From 50871d1a9253c571cd20fb2f4ba88490345c986b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=C3=A4schle?= Date: Tue, 14 Apr 2020 19:37:56 +0200 Subject: [PATCH] checker: for in index type error position --- vlib/v/checker/checker.v | 2 +- vlib/v/checker/tests/inout/for-in-index-type.out | 6 ++++++ vlib/v/checker/tests/inout/for-in-index-type.vv | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 vlib/v/checker/tests/inout/for-in-index-type.out create mode 100644 vlib/v/checker/tests/inout/for-in-index-type.vv 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