From 8ac00b8711d58a58bd0f97d788f4325d358c72a2 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 24 Jun 2020 16:54:21 +0200 Subject: [PATCH] parser: check for loop key/val names --- vlib/v/parser/for.v | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vlib/v/parser/for.v b/vlib/v/parser/for.v index 788162904b..2cdebd9324 100644 --- a/vlib/v/parser/for.v +++ b/vlib/v/parser/for.v @@ -73,6 +73,9 @@ fn (mut p Parser) for_stmt() ast.Stmt { key_var_name = val_var_name val_var_pos = p.tok.position() val_var_name = p.check_name() + if key_var_name == val_var_name { + p.error_with_pos('key and value in a for loop cannot be the same', val_var_pos) + } if p.scope.known_var(key_var_name) { p.error('redefinition of key iteration variable `$key_var_name`') }