1
0
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:
yuyi 2021-06-06 22:40:13 +08:00 committed by GitHub
parent c14b357fec
commit 114c382c46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 0 deletions

View File

@ -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++
}

View File

@ -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'
}