1
0
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:
yuyi 2023-01-19 00:59:02 +08:00 committed by GitHub
parent 525c5e237a
commit 6688c0f3d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 2 deletions

View File

@ -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 {

View File

@ -0,0 +1,12 @@
MyStruct[int]{
a: 0
}
MyStructAlias(MyStruct[int]{
a: 0
})
MyStruct[int]{
a: 0
}
MyStructAlias(MyStruct[int]{
a: 0
})

View 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
}