diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index ccd538412e..3cfef671ff 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -7744,6 +7744,7 @@ pub fn (mut c Checker) map_init(mut node ast.MapInit) ast.Type { continue } val := node.vals[i] + c.expected_type = key0_type key_type := c.expr(key) c.expected_type = val0_type val_type := c.expr(val) diff --git a/vlib/v/tests/map_init_with_enum_keys_test.v b/vlib/v/tests/map_init_with_enum_keys_test.v new file mode 100644 index 0000000000..067945126d --- /dev/null +++ b/vlib/v/tests/map_init_with_enum_keys_test.v @@ -0,0 +1,20 @@ +enum En { + ea + eb +} + +struct St { +mut: + m map[En]string +} + +fn test_map_init_with_enum_keys() { + mut st := St{} + + st.m = { + .ea: 'a' + } + + println(st.m) + assert '$st.m' == "{ea: 'a'}" +}