diff --git a/vlib/v/checker/check_types.v b/vlib/v/checker/check_types.v index c2363644ad..41a025f659 100644 --- a/vlib/v/checker/check_types.v +++ b/vlib/v/checker/check_types.v @@ -865,7 +865,7 @@ fn (mut c Checker) infer_fn_generic_types(func ast.Fn, mut node ast.CallExpr) { if param.typ.has_flag(.generic) && param_type_sym.name == gt_name { typ = ast.mktyp(arg.typ) - sym := c.table.sym(arg.typ) + sym := c.table.final_sym(arg.typ) if sym.info is ast.FnType { mut func_ := sym.info.func func_.name = '' @@ -898,7 +898,7 @@ fn (mut c Checker) infer_fn_generic_types(func ast.Fn, mut node ast.CallExpr) { typ = typ.set_nr_muls(0) } } else if param.typ.has_flag(.generic) { - arg_sym := c.table.sym(arg.typ) + arg_sym := c.table.final_sym(arg.typ) if param.typ.has_flag(.variadic) { typ = ast.mktyp(arg.typ) } else if arg_sym.kind == .array && param_type_sym.kind == .array { diff --git a/vlib/v/slow_tests/inout/generic_fn_with_alias_arg.out b/vlib/v/slow_tests/inout/generic_fn_with_alias_arg.out new file mode 100644 index 0000000000..e82bd32020 --- /dev/null +++ b/vlib/v/slow_tests/inout/generic_fn_with_alias_arg.out @@ -0,0 +1,12 @@ +MyStruct[int]{ + a: 0 +} +MyStructAlias(MyStruct[int]{ + a: 0 +}) +MyStruct[int]{ + a: 0 +} +MyStructAlias(MyStruct[int]{ + a: 0 +}) diff --git a/vlib/v/slow_tests/inout/generic_fn_with_alias_arg.vv b/vlib/v/slow_tests/inout/generic_fn_with_alias_arg.vv new file mode 100644 index 0000000000..9db6449fbd --- /dev/null +++ b/vlib/v/slow_tests/inout/generic_fn_with_alias_arg.vv @@ -0,0 +1,23 @@ +struct MyStruct[T] { + a T +} + +fn mprint[T](s MyStruct[T]) { + println(s) +} + +fn mprint_with_alias(s MyStructAlias) { + println(s) +} + +type MyStructAlias = MyStruct[int] + +fn main() { + a := MyStruct[int]{} + mprint(a) // works + mprint_with_alias(a) // works + + b := MyStructAlias{} + mprint(b) // does not work, requires mprint[int](b) + mprint_with_alias(b) // works +}