1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix return typeof[T]() in generic functions (#16626)

This commit is contained in:
Felipe Pena 2022-12-09 12:24:47 -03:00 committed by GitHub
parent 6c0f22416f
commit ba8e61ebf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -3525,9 +3525,7 @@ fn (mut g Gen) typeof_expr(node ast.TypeOf) {
varg_elem_type_sym := g.table.sym(g.table.value_type(typ))
g.write('_SLIT("...${util.strip_main_name(varg_elem_type_sym.name)}")')
} else {
x := g.table.type_to_str(typ)
y := util.strip_main_name(x)
g.write('_SLIT("${y}")')
g.type_name(typ)
}
}

View File

@ -0,0 +1,12 @@
fn foo[T]() string {
return typeof[T]().name
}
fn bar[T]() string {
return typeof[T]()
}
fn test_main() {
assert foo[int]() == 'int'
assert bar[int]() == 'int'
}