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:
parent
6c0f22416f
commit
ba8e61ebf3
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
12
vlib/v/tests/fn_return_typeof_test.v
Normal file
12
vlib/v/tests/fn_return_typeof_test.v
Normal 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'
|
||||
}
|
Loading…
Reference in New Issue
Block a user