checker: fix map init with enum keys (#12637)

pull/12647/head
yuyi 2021-12-02 00:11:50 +08:00 committed by GitHub
parent 8494e387ec
commit 988779846f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -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)

View 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'}"
}