Skip to content

Commit 03e89b7

Browse files
authored
checker: add error for field map (i.e. a plain untyped map), used inside a struct (#21625)
1 parent ca55da6 commit 03e89b7

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

vlib/v/checker/tests/map_def_err.out

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
vlib/v/checker/tests/map_def_err.vv:2:7: error: cannot use the map type without key and value definition
2+
1 | struct Foo {
3+
2 | bar map
4+
| ~~~
5+
3 | }

vlib/v/checker/tests/map_def_err.vv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
struct Foo {
2+
bar map
3+
}

vlib/v/parser/parse_type.v

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ fn (mut p Parser) parse_map_type() ast.Type {
116116
}
117117
p.next()
118118
if p.tok.kind != .lsbr {
119+
if p.inside_struct_field_decl {
120+
p.error_with_pos('cannot use the map type without key and value definition',
121+
p.prev_tok.pos())
122+
return 0
123+
}
119124
return ast.map_type
120125
}
121126
p.check(.lsbr)

0 commit comments

Comments
 (0)