cgen: fix generic fn with anon fn in body (#12647)

pull/12644/head
yuyi 2021-12-02 16:53:42 +08:00 committed by GitHub
parent 988779846f
commit 2144471ce1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -217,7 +217,9 @@ fn (mut g Gen) gen_fn_decl(node &ast.FnDecl, skip bool) {
}
mut type_name := g.typ(node.return_type)
name = g.generic_fn_name(g.cur_concrete_types, name, true)
if node.generic_names.len > 0 {
name = g.generic_fn_name(g.cur_concrete_types, name, true)
}
if g.pref.translated && node.attrs.contains('c') {
// This fixes unknown symbols errors when building separate .c => .v files

View File

@ -0,0 +1,11 @@
fn foo<T>() string {
x := fn () string {
return 'ok'
}
return x()
}
fn test_generic_fn_with_anon_fn() {
ret := foo<int>()
assert ret == 'ok'
}