From 6153df561db504c615a4f73626df0244c2b51757 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sat, 1 Jun 2024 10:03:52 -0300 Subject: [PATCH] fix --- 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 00000000000000..51c5ffc36326d6 --- /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 00000000000000..e3ec084bd49217 --- /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 9607ba6c3ff399..0855929f8716ef 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)