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:
parent
828cd4fe79
commit
f4cd3931fb
@ -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
|
||||
|
24
vlib/v/tests/dump_on_generic_func_test.v
Normal file
24
vlib/v/tests/dump_on_generic_func_test.v
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user