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

cgen: fix dump fn name using generic var (#16805)

This commit is contained in:
Felipe Pena 2022-12-30 06:16:59 -03:00 committed by GitHub
parent 828cd4fe79
commit f4cd3931fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View File

@ -15,6 +15,16 @@ fn (mut g Gen) dump_expr(node ast.DumpExpr) {
mut name := node.cname
mut expr_type := node.expr_type
if g.cur_fn != unsafe { nil } && g.cur_fn.generic_names.len > 0 {
// generic func with recursion rewrite node.expr_type
if node.expr is ast.Ident {
// var
if (node.expr as ast.Ident).info is ast.IdentVar && (node.expr as ast.Ident).language == .v {
name = g.typ(g.unwrap_generic((node.expr as ast.Ident).info.typ)).replace('*',
'')
}
}
}
// var.${field.name}
if node.expr is ast.ComptimeSelector {
selector := node.expr as ast.ComptimeSelector

View File

@ -0,0 +1,24 @@
struct Aa {
sub AliasType
}
type AliasType = Bb
struct Bb {
a int
}
fn encode_struct[U](val U) {
dump(val)
println(val)
$for field in U.fields {
encode_struct(val.$(field.name))
}
}
fn test_main() {
aa := Aa{}
encode_struct(aa)
assert true
}