From 03e89b78512880a0f59117b17a71e21192d51659 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sat, 1 Jun 2024 19:34:41 -0300 Subject: [PATCH] checker: add error for `field map` (i.e. a plain untyped map), used inside a struct (#21625) --- vlib/v/checker/tests/map_def_err.out | 5 +++++ vlib/v/checker/tests/map_def_err.vv | 3 +++ vlib/v/parser/parse_type.v | 5 +++++ 3 files changed, 13 insertions(+) create mode 100644 vlib/v/checker/tests/map_def_err.out create mode 100644 vlib/v/checker/tests/map_def_err.vv diff --git a/vlib/v/checker/tests/map_def_err.out b/vlib/v/checker/tests/map_def_err.out new file mode 100644 index 000000000..51c5ffc36 --- /dev/null +++ b/vlib/v/checker/tests/map_def_err.out @@ -0,0 +1,5 @@ +vlib/v/checker/tests/map_def_err.vv:2:7: error: cannot use the map type without key and value definition + 1 | struct Foo { + 2 | bar map + | ~~~ + 3 | } diff --git a/vlib/v/checker/tests/map_def_err.vv b/vlib/v/checker/tests/map_def_err.vv new file mode 100644 index 000000000..e3ec084bd --- /dev/null +++ b/vlib/v/checker/tests/map_def_err.vv @@ -0,0 +1,3 @@ +struct Foo { + bar map +} diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v index 9607ba6c3..0855929f8 100644 --- a/vlib/v/parser/parse_type.v +++ b/vlib/v/parser/parse_type.v @@ -116,6 +116,11 @@ fn (mut p Parser) parse_map_type() ast.Type { } p.next() if p.tok.kind != .lsbr { + if p.inside_struct_field_decl { + p.error_with_pos('cannot use the map type without key and value definition', + p.prev_tok.pos()) + return 0 + } return ast.map_type } p.check(.lsbr) -- 2.39.5