From 41eb4453e3b6f4c8c794848efd437d4e2e300000 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sun, 26 Apr 2020 12:01:10 +0200 Subject: [PATCH] parser: do not allow redefinition of fn args --- vlib/v/parser/fn.v | 3 +++ vlib/v/tests/nested_map_test.v | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index d35c29a906..8317f1ade6 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -158,6 +158,9 @@ fn (mut p Parser) fn_decl() ast.FnDecl { args2, is_variadic := p.fn_args() args << args2 for i, arg in args { + if p.scope.known_var(arg.name) { + p.error('redefinition of parameter `$arg.name`') + } p.scope.register(arg.name, ast.Var{ name: arg.name typ: arg.typ diff --git a/vlib/v/tests/nested_map_test.v b/vlib/v/tests/nested_map_test.v index 92f3a1f282..c193cd6d28 100644 --- a/vlib/v/tests/nested_map_test.v +++ b/vlib/v/tests/nested_map_test.v @@ -9,7 +9,7 @@ fn test_nested_maps() { assert x["a"]["b"] == 5 x["a"]["b"] = 7 assert x["a"]["b"] == 7 - y := map[string]map[string]map[string]int + mut y := map[string]map[string]map[string]int y["a"] = map[string]map[string]int y["a"]["b"] = map[string]int assert y["a"]["b"]["c"] == 0