diff --git a/vlib/v/checker/containers.v b/vlib/v/checker/containers.v index 17bfa99aab..8db74f7501 100644 --- a/vlib/v/checker/containers.v +++ b/vlib/v/checker/containers.v @@ -202,7 +202,7 @@ pub fn (mut c Checker) map_init(mut node ast.MapInit) ast.Type { sym := c.table.sym(c.expected_type) if sym.kind == .map { info := sym.map_info() - node.typ = c.expected_type + node.typ = c.expected_type.clear_flag(.optional) node.key_type = info.key_type node.value_type = info.value_type return node.typ diff --git a/vlib/v/tests/option_empty_map_test.v b/vlib/v/tests/option_empty_map_test.v new file mode 100644 index 0000000000..fd5ad743e7 --- /dev/null +++ b/vlib/v/tests/option_empty_map_test.v @@ -0,0 +1,13 @@ +fn opt() ?map[string]string { + return {} +} + +fn test_option_empty_map() { + x := opt() or { + assert false + return + } + + dump(x) + assert '$x' == '{}' +}