mirror of
https://github.com/vlang/v.git
synced 2025-09-11 16:36:20 -04:00
parent
a8a4507237
commit
a59b717daa
@ -980,6 +980,16 @@ fn (mut g Gen) call_expr(node ast.CallExpr) {
|
||||
ret_typ = g.unwrap_generic(ret_sym.info.elem_type).derive(unwrapped_ret_typ)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
r_typ := g.resolve_return_type(node)
|
||||
if r_typ != ast.void_type && !r_typ.has_flag(.generic) {
|
||||
// restore result/option flag, as `resolve_return_type` may clean them
|
||||
if node.return_type.has_flag(.result) {
|
||||
ret_typ = r_typ.set_flag(.result)
|
||||
} else {
|
||||
ret_typ = r_typ.set_flag(.option)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
mut styp := g.styp(ret_typ)
|
||||
|
15
vlib/v/tests/generics/generics_return_result_maps_test.v
Normal file
15
vlib/v/tests/generics/generics_return_result_maps_test.v
Normal file
@ -0,0 +1,15 @@
|
||||
fn decode_map[K, V](a map[K]V) !map[K]V {
|
||||
return a
|
||||
}
|
||||
|
||||
fn decode[T]() !T {
|
||||
return decode_map(T{})!
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
x_str_str := decode[map[string]string]() or { panic(err) }
|
||||
x_str_int := decode[map[string]int]() or { panic(err) }
|
||||
|
||||
assert typeof(x_str_str).name == 'map[string]string'
|
||||
assert typeof(x_str_int).name == 'map[string]int'
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user