mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
ac4791045f
commit
1a838b1f43
@ -5417,6 +5417,7 @@ pub fn (mut c Checker) map_init(mut node ast.MapInit) table.Type {
|
||||
}
|
||||
val := node.vals[i]
|
||||
key_type := c.expr(key)
|
||||
c.expected_type = val0_type
|
||||
val_type := c.expr(val)
|
||||
if !c.check_types(key_type, key0_type) {
|
||||
msg := c.expected_msg(key_type, key0_type)
|
||||
|
24
vlib/v/tests/match_in_map_init_test.v
Normal file
24
vlib/v/tests/match_in_map_init_test.v
Normal file
@ -0,0 +1,24 @@
|
||||
fn test_match_in_map_init() {
|
||||
ret := foo()
|
||||
println(ret)
|
||||
assert ret == map{'token': 'a', 'sleep': '30', 'every': '1'}
|
||||
}
|
||||
|
||||
fn foo() map[string]string {
|
||||
mut cfg := map[string][]string{}
|
||||
cfg['token'] = ['a', 'b']
|
||||
cfg['sleep'] = ['30', '60']
|
||||
cfg['every'] = ['1', '5']
|
||||
|
||||
return map{
|
||||
'token': cfg['token'][0]
|
||||
'sleep': match cfg['sleep'][0].len {
|
||||
0 { '60' }
|
||||
else { cfg['sleep'][0] }
|
||||
}
|
||||
'every': match cfg['every'][0].len {
|
||||
0 { '5' }
|
||||
else { cfg['every'][0] }
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user