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() {
|
||||
|
@ -5551,6 +5555,8 @@ pub fn (mut c Checker) map_init(mut node ast.MapInit) table.Type {
|
|||
node.value_type = val0_type
|
||||
return map_type
|
||||
}
|
||||
return node.typ
|
||||
}
|
||||
|
||||
// call this *before* calling error or warn
|
||||
pub fn (mut c Checker) add_error_detail(s string) {
|
||||
|
|
|
@ -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 | }
|
|
@ -0,0 +1,4 @@
|
|||
fn main() {
|
||||
a := map{}
|
||||
println(a)
|
||||
}
|
Loading…
Reference in New Issue