mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: fix generic fn typeof name (#10363)
This commit is contained in:
parent
c14b357fec
commit
114c382c46
@ -578,6 +578,15 @@ fn (mut p Parser) parse_generic_names() []string {
|
||||
}
|
||||
p.check(.name)
|
||||
param_names << name
|
||||
if p.table.find_type_idx(name) == 0 {
|
||||
p.table.register_type_symbol(ast.TypeSymbol{
|
||||
name: name
|
||||
cname: util.no_dots(name)
|
||||
mod: p.mod
|
||||
kind: .any
|
||||
is_public: true
|
||||
})
|
||||
}
|
||||
first_done = true
|
||||
count++
|
||||
}
|
||||
|
@ -13,3 +13,31 @@ fn test_generics_fn_typeof_name() {
|
||||
println(ret)
|
||||
assert ret == 'fn (mut Client, string)'
|
||||
}
|
||||
|
||||
// test no paras generics fn typeof name
|
||||
struct Test1 {}
|
||||
|
||||
struct Test2 {}
|
||||
|
||||
fn print_type<T>() string {
|
||||
name := T.name
|
||||
println(name)
|
||||
return name
|
||||
}
|
||||
|
||||
fn test_no_paras_generics_fn_typeof_name() {
|
||||
mut ret := print_type<Test1>()
|
||||
assert ret == 'Test1'
|
||||
|
||||
ret = print_type<Test2>()
|
||||
assert ret == 'Test2'
|
||||
|
||||
ret = print_type<int>()
|
||||
assert ret == 'int'
|
||||
|
||||
ret = print_type<f32>()
|
||||
assert ret == 'f32'
|
||||
|
||||
ret = print_type<bool>()
|
||||
assert ret == 'bool'
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user