mirror of
https://github.com/vlang/v.git
synced 2025-09-19 12:27:02 -04:00
parser: sugggest map initialization with the correct syntax (#21817)
This commit is contained in:
parent
df18047347
commit
f6de36db51
@ -163,7 +163,9 @@ fn (mut p Parser) parse_map_type() ast.Type {
|
|||||||
p.check(.rsbr)
|
p.check(.rsbr)
|
||||||
if p.tok.kind == .lsbr {
|
if p.tok.kind == .lsbr {
|
||||||
if p.peek_tok.kind !in [.rsbr, .number] {
|
if p.peek_tok.kind !in [.rsbr, .number] {
|
||||||
p.error_with_pos('maps can only have a single key', p.peek_tok.pos())
|
s := p.table.type_to_str(key_type)
|
||||||
|
p.error_with_pos('maps can only have a single key. To declare a map use `map[${s}]${p.peek_tok.lit}{}` instead',
|
||||||
|
p.peek_tok.pos())
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
vlib/v/parser/tests/map_key_twice_err.vv:1:14: error: maps can only have a single key
|
vlib/v/parser/tests/map_key_twice_err.vv:1:14: error: maps can only have a single key. To declare a map use `map[u8]u8{}` instead
|
||||||
1 | _ := map[u8][u8]{}
|
1 | _ := map[u8][u8]{}
|
||||||
| ~~
|
| ~~
|
||||||
2 |
|
2 |
|
||||||
|
Loading…
x
Reference in New Issue
Block a user