checker: check invalid map variable name (#12474)

pull/12481/head
yuyi 2021-11-16 14:42:49 +08:00 committed by GitHub
parent 2f75ce0d4c
commit 9565adf597
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 2 deletions

View File

@ -32,7 +32,7 @@ const (
array_builtin_methods = ['filter', 'clone', 'repeat', 'reverse', 'map', 'slice', array_builtin_methods = ['filter', 'clone', 'repeat', 'reverse', 'map', 'slice',
'sort', 'contains', 'index', 'wait', 'any', 'all', 'first', 'last', 'pop'] 'sort', 'contains', 'index', 'wait', 'any', 'all', 'first', 'last', 'pop']
reserved_type_names = ['bool', 'i8', 'i16', 'int', 'i64', 'byte', 'u16', 'u32', 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' vroot_is_deprecated_message = '@VROOT is deprecated, use @VMODROOT or @VEXEROOT instead'
) )

View File

@ -31,4 +31,11 @@ vlib/v/checker/tests/invalid_variable_name_err.vv:14:2: error: invalid use of re
14 | f64 := 2.22 14 | f64 := 2.22
| ~~~ | ~~~
15 | println(f64) 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 | }

View File

@ -13,4 +13,7 @@ fn main() {
f64 := 2.22 f64 := 2.22
println(f64) println(f64)
map := map[string]string
println(map)
} }