Skip to content

Commit

Permalink
parser: sugggest map initialization with the correct syntax (vlang#21817
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Delta456 authored Jul 7, 2024
1 parent df18047 commit f6de36d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion vlib/v/parser/parse_type.v
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ fn (mut p Parser) parse_map_type() ast.Type {
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())
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
}
}
Expand Down
2 changes: 1 addition & 1 deletion vlib/v/parser/tests/map_key_twice_err.out
Original file line number Diff line number Diff line change
@@ -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]{}
| ~~
2 |

0 comments on commit f6de36d

Please sign in to comment.