mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
9a7d9e047b
commit
10c9f61d61
@ -5501,6 +5501,9 @@ pub fn (mut c Checker) map_init(mut node ast.MapInit) table.Type {
|
||||
node.key_type = info.key_type
|
||||
node.value_type = info.value_type
|
||||
return node.typ
|
||||
} else {
|
||||
c.error('invalid empty map initilization syntax, use e.g. map[string]int{} instead',
|
||||
node.pos)
|
||||
}
|
||||
}
|
||||
// `x := map[string]string` - set in parser
|
||||
@ -5512,6 +5515,7 @@ pub fn (mut c Checker) map_init(mut node ast.MapInit) table.Type {
|
||||
node.value_type = info.value_type
|
||||
return node.typ
|
||||
}
|
||||
if node.keys.len > 0 && node.vals.len > 0 {
|
||||
// `{'age': 20}`
|
||||
mut key0_type := c.table.mktyp(c.expr(node.keys[0]))
|
||||
if node.keys[0].is_auto_deref_var() {
|
||||
@ -5550,6 +5554,8 @@ pub fn (mut c Checker) map_init(mut node ast.MapInit) table.Type {
|
||||
node.key_type = key0_type
|
||||
node.value_type = val0_type
|
||||
return map_type
|
||||
}
|
||||
return node.typ
|
||||
}
|
||||
|
||||
// call this *before* calling error or warn
|
||||
|
6
vlib/v/checker/tests/map_init_invalid_syntax.out
Normal file
6
vlib/v/checker/tests/map_init_invalid_syntax.out
Normal file
@ -0,0 +1,6 @@
|
||||
vlib/v/checker/tests/map_init_invalid_syntax.vv:2:10: error: invalid empty map initilization syntax, use e.g. map[string]int{} instead
|
||||
1 | fn main() {
|
||||
2 | a := map{}
|
||||
| ~~
|
||||
3 | println(a)
|
||||
4 | }
|
4
vlib/v/checker/tests/map_init_invalid_syntax.vv
Normal file
4
vlib/v/checker/tests/map_init_invalid_syntax.vv
Normal file
@ -0,0 +1,4 @@
|
||||
fn main() {
|
||||
a := map{}
|
||||
println(a)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user