mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
parser: disallow defining map key more than once (#20905)
This commit is contained in:
parent
9703029dbe
commit
43e96ce5bb
3 changed files with 12 additions and 0 deletions
|
@ -140,6 +140,12 @@ fn (mut p Parser) parse_map_type() ast.Type {
|
|||
return 0
|
||||
}
|
||||
p.check(.rsbr)
|
||||
if p.tok.kind == .lsbr {
|
||||
if p.peek_tok.kind !in [.rsbr, .number] {
|
||||
p.error_with_pos('maps can only have a single key', p.peek_tok.pos())
|
||||
return 0
|
||||
}
|
||||
}
|
||||
value_type := p.parse_type()
|
||||
if value_type.idx() == 0 {
|
||||
// error is reported in parse_type
|
||||
|
|
4
vlib/v/parser/tests/map_key_twice_err.out
Normal file
4
vlib/v/parser/tests/map_key_twice_err.out
Normal file
|
@ -0,0 +1,4 @@
|
|||
vlib/v/parser/tests/map_key_twice_err.vv:1:14: error: maps can only have a single key
|
||||
1 | _ := map[u8][u8]{}
|
||||
| ~~
|
||||
2 |
|
2
vlib/v/parser/tests/map_key_twice_err.vv
Normal file
2
vlib/v/parser/tests/map_key_twice_err.vv
Normal file
|
@ -0,0 +1,2 @@
|
|||
_ := map[u8][u8]{}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue