mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix generic fn infering map argument (#18341)
This commit is contained in:
parent
8d2a0ffe37
commit
0e106c9062
@ -344,7 +344,8 @@ fn (mut c Checker) map_init(mut node ast.MapInit) ast.Type {
|
|||||||
mut key0_type := ast.void_type
|
mut key0_type := ast.void_type
|
||||||
mut val0_type := ast.void_type
|
mut val0_type := ast.void_type
|
||||||
use_expected_type := c.expected_type != ast.void_type && !c.inside_const
|
use_expected_type := c.expected_type != ast.void_type && !c.inside_const
|
||||||
&& c.table.sym(c.expected_type).kind == .map
|
&& c.table.sym(c.expected_type).kind == .map && !(c.inside_fn_arg
|
||||||
|
&& c.expected_type.has_flag(.generic))
|
||||||
if use_expected_type {
|
if use_expected_type {
|
||||||
sym := c.table.sym(c.expected_type)
|
sym := c.table.sym(c.expected_type)
|
||||||
info := sym.map_info()
|
info := sym.map_info()
|
||||||
|
17
vlib/v/tests/generic_fn_infer_map_argument_test.v
Normal file
17
vlib/v/tests/generic_fn_infer_map_argument_test.v
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
fn f[T](src map[string]T) T {
|
||||||
|
return src['a']
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_generic_fn_infer_map_arg() {
|
||||||
|
r1 := f({
|
||||||
|
'a': 1
|
||||||
|
})
|
||||||
|
println(r1)
|
||||||
|
assert r1 == 1
|
||||||
|
|
||||||
|
r2 := f({
|
||||||
|
'a': 'hello'
|
||||||
|
})
|
||||||
|
println(r2)
|
||||||
|
assert r2 == 'hello'
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user