mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix generic fn infering error with alias argument (#17026)
This commit is contained in:
parent
525c5e237a
commit
6688c0f3d7
@ -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 {
|
||||
|
12
vlib/v/slow_tests/inout/generic_fn_with_alias_arg.out
Normal file
12
vlib/v/slow_tests/inout/generic_fn_with_alias_arg.out
Normal file
@ -0,0 +1,12 @@
|
||||
MyStruct[int]{
|
||||
a: 0
|
||||
}
|
||||
MyStructAlias(MyStruct[int]{
|
||||
a: 0
|
||||
})
|
||||
MyStruct[int]{
|
||||
a: 0
|
||||
}
|
||||
MyStructAlias(MyStruct[int]{
|
||||
a: 0
|
||||
})
|
23
vlib/v/slow_tests/inout/generic_fn_with_alias_arg.vv
Normal file
23
vlib/v/slow_tests/inout/generic_fn_with_alias_arg.vv
Normal file
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user