From 9565adf5978d3d271b90a922fcde28c975b5cef5 Mon Sep 17 00:00:00 2001 From: yuyi Date: Tue, 16 Nov 2021 14:42:49 +0800 Subject: [PATCH] checker: check invalid map variable name (#12474) --- vlib/v/checker/checker.v | 2 +- vlib/v/checker/tests/invalid_variable_name_err.out | 9 ++++++++- vlib/v/checker/tests/invalid_variable_name_err.vv | 3 +++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index b0fd0d512f..747a157b7c 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -32,7 +32,7 @@ const ( array_builtin_methods = ['filter', 'clone', 'repeat', 'reverse', 'map', 'slice', 'sort', 'contains', 'index', 'wait', 'any', 'all', 'first', 'last', 'pop'] reserved_type_names = ['bool', 'i8', 'i16', 'int', 'i64', 'byte', 'u16', 'u32', - 'u64', 'f32', 'f64', 'string', 'rune'] + 'u64', 'f32', 'f64', 'map', 'string', 'rune'] vroot_is_deprecated_message = '@VROOT is deprecated, use @VMODROOT or @VEXEROOT instead' ) diff --git a/vlib/v/checker/tests/invalid_variable_name_err.out b/vlib/v/checker/tests/invalid_variable_name_err.out index 4eb686d61a..0e90e11f49 100644 --- a/vlib/v/checker/tests/invalid_variable_name_err.out +++ b/vlib/v/checker/tests/invalid_variable_name_err.out @@ -31,4 +31,11 @@ vlib/v/checker/tests/invalid_variable_name_err.vv:14:2: error: invalid use of re 14 | f64 := 2.22 | ~~~ 15 | println(f64) - 16 | } + 16 | +vlib/v/checker/tests/invalid_variable_name_err.vv:17:2: error: invalid use of reserved type `map` as a variable name + 15 | println(f64) + 16 | + 17 | map := map[string]string + | ~~~ + 18 | println(map) + 19 | } diff --git a/vlib/v/checker/tests/invalid_variable_name_err.vv b/vlib/v/checker/tests/invalid_variable_name_err.vv index 92056ad91e..e2260f0a62 100644 --- a/vlib/v/checker/tests/invalid_variable_name_err.vv +++ b/vlib/v/checker/tests/invalid_variable_name_err.vv @@ -13,4 +13,7 @@ fn main() { f64 := 2.22 println(f64) + + map := map[string]string + println(map) }