diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 26941fc3ff..52f7f39775 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -2888,13 +2888,14 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) } } // resolve return generics struct to concrete type - if func.generic_names.len > 0 && func.return_type.has_flag(.generic) { + if func.generic_names.len > 0 && func.return_type.has_flag(.generic) + && c.table.cur_fn.generic_names.len == 0 { node.return_type = c.table.unwrap_generic_type(func.return_type, func.generic_names, concrete_types) } else { node.return_type = func.return_type } - if node.concrete_types.len > 0 && func.return_type != 0 { + if node.concrete_types.len > 0 && func.return_type != 0 && c.table.cur_fn.generic_names.len == 0 { if typ := c.table.resolve_generic_to_concrete(func.return_type, func.generic_names, concrete_types) { diff --git a/vlib/v/tests/generics_with_assign_nested_generics_call_test.v b/vlib/v/tests/generics_with_assign_nested_generics_call_test.v new file mode 100644 index 0000000000..54b34c6b54 --- /dev/null +++ b/vlib/v/tests/generics_with_assign_nested_generics_call_test.v @@ -0,0 +1,37 @@ +struct SSS { +mut: + x T +} + +fn (s SSS) inner() T { + return s.x +} + +fn (s SSS) outer() string { + ret := s.inner() + println(ret) + return '$ret' +} + +fn test_generics_with_assign_nested_generic_method_call() { + s1 := SSS{100} + assert s1.outer() == '100' + + s2 := SSS{'hello'} + assert s2.outer() == 'hello' +} + +fn fn_inner(t T) T { + return t +} + +fn fn_outer(t T) string { + ret := fn_inner(t) + println(ret) + return '$ret' +} + +fn test_generics_with_assign_nested_generic_fn_call() { + assert fn_outer(100) == '100' + assert fn_outer('hello') == 'hello' +} diff --git a/vlib/v/tests/generics_with_nested_generics_method_call_assign_test.v b/vlib/v/tests/generics_with_nested_generics_method_call_assign_test.v deleted file mode 100644 index 99c3c108bf..0000000000 --- a/vlib/v/tests/generics_with_nested_generics_method_call_assign_test.v +++ /dev/null @@ -1,24 +0,0 @@ -struct SSS { -mut: - x T -} - -fn (s SSS) inner() T { - return s.x -} - -fn (s SSS) outer() string { - ret := s.inner() - println(ret) - return '$ret' -} - -fn test_generics_with_nested_generic_method_call_assign() { - s1 := SSS{100} - s1.outer() - assert s1.outer() == '100' - - s2 := SSS{'hello'} - s2.outer() - assert s2.outer() == 'hello' -}