diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index c65994e35b..40a12bebc9 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -699,6 +699,24 @@ fn (mut c Checker) unwrap_generic_type(typ ast.Type, generic_names []string, con idx := c.table.find_or_register_array_with_dims(unwrap_typ, dims) return ast.new_type(idx).derive_add_muls(typ).clear_flag(.generic) } + ast.ArrayFixed { + unwrap_typ := c.unwrap_generic_type(ts.info.elem_type, generic_names, concrete_types) + idx := c.table.find_or_register_array_fixed(unwrap_typ, ts.info.size, ast.None{}) + return ast.new_type(idx).derive_add_muls(typ).clear_flag(.generic) + } + ast.Chan { + unwrap_typ := c.unwrap_generic_type(ts.info.elem_type, generic_names, concrete_types) + idx := c.table.find_or_register_chan(unwrap_typ, unwrap_typ.nr_muls() > 0) + return ast.new_type(idx).derive_add_muls(typ).clear_flag(.generic) + } + ast.Map { + unwrap_key_type := c.unwrap_generic_type(ts.info.key_type, generic_names, + concrete_types) + unwrap_value_type := c.unwrap_generic_type(ts.info.value_type, generic_names, + concrete_types) + idx := c.table.find_or_register_map(unwrap_key_type, unwrap_value_type) + return ast.new_type(idx).derive_add_muls(typ).clear_flag(.generic) + } ast.Struct, ast.Interface, ast.SumType { if !ts.info.is_generic { return typ diff --git a/vlib/v/tests/generics_fn_return_array_of_generic_struct_test.v b/vlib/v/tests/generics_fn_return_array_of_generic_struct_test.v deleted file mode 100644 index bf7e4ddae9..0000000000 --- a/vlib/v/tests/generics_fn_return_array_of_generic_struct_test.v +++ /dev/null @@ -1,12 +0,0 @@ -pub struct Abcd { -} - -pub fn iterators() []&Abcd { - return []&Abcd{} -} - -fn test_generic_fn_return_array_of_generic_struct() { - a := iterators() - println(a) - assert '$a' == '[]' -} diff --git a/vlib/v/tests/generics_fn_return_types_with_generic_struct_test.v b/vlib/v/tests/generics_fn_return_types_with_generic_struct_test.v new file mode 100644 index 0000000000..e0f37a00a3 --- /dev/null +++ b/vlib/v/tests/generics_fn_return_types_with_generic_struct_test.v @@ -0,0 +1,32 @@ +struct Abcd { +} + +fn iterators_array() []&Abcd { + return []&Abcd{} +} + +fn test_generic_fn_return_array_of_generic_struct() { + a := iterators_array() + println(a) + assert '$a' == '[]' +} + +fn iterators_chan() chan Abcd { + return chan Abcd{} +} + +fn test_generic_fn_return_chan_of_generic_struct() { + a := iterators_chan() + println(a) + assert typeof(a).name == 'chan Abcd' +} + +fn iterators_map() map[string]&Abcd { + return map[string]&Abcd{} +} + +fn test_generic_fn_return_map_of_generic_struct() { + a := iterators_map() + println(a) + assert '$a' == '{}' +}