diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v index 839b30405e..6d82857192 100644 --- a/vlib/v/parser/parse_type.v +++ b/vlib/v/parser/parse_type.v @@ -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 diff --git a/vlib/v/parser/tests/map_key_twice_err.out b/vlib/v/parser/tests/map_key_twice_err.out new file mode 100644 index 0000000000..05bd066dee --- /dev/null +++ b/vlib/v/parser/tests/map_key_twice_err.out @@ -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 | diff --git a/vlib/v/parser/tests/map_key_twice_err.vv b/vlib/v/parser/tests/map_key_twice_err.vv new file mode 100644 index 0000000000..df6a937845 --- /dev/null +++ b/vlib/v/parser/tests/map_key_twice_err.vv @@ -0,0 +1,2 @@ +_ := map[u8][u8]{} +