mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix map init with enum keys (#12637)
This commit is contained in:
parent
8494e387ec
commit
988779846f
@ -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)
|
||||
|
20
vlib/v/tests/map_init_with_enum_keys_test.v
Normal file
20
vlib/v/tests/map_init_with_enum_keys_test.v
Normal file
@ -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'}"
|
||||
}
|
Loading…
Reference in New Issue
Block a user