Skip to content

Commit

Permalink
cgen: cleanup in expr_with_tmp_var() (#20626)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Jan 22, 2024
1 parent 1253b06 commit 9e8a159
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions vlib/v/gen/c/cgen.v
Expand Up @@ -1956,14 +1956,20 @@ fn (mut g Gen) expr_with_tmp_var(expr ast.Expr, expr_typ ast.Type, ret_typ ast.T
if ret_typ.has_flag(.generic) {
if expr is ast.SelectorExpr && g.cur_concrete_types.len == 0 {
// resolve generic struct on selectorExpr inside non-generic function
if expr.expr is ast.Ident && expr.expr.obj is ast.Var {
if (expr.expr.obj as ast.Var).expr is ast.StructInit {
g.cur_concrete_types << (g.table.sym(expr.expr.obj.typ).info as ast.Struct).concrete_types
if expr.expr is ast.Ident {
if expr.expr.obj is ast.Var {
if expr.expr.obj.expr is ast.StructInit {
struct_info := g.table.sym(expr.expr.obj.typ).info
if struct_info is ast.Struct {
g.cur_concrete_types << struct_info.concrete_types
}
}
}
}
}
styp = g.base_type(g.unwrap_generic(ret_typ))
ret_styp := g.typ(g.unwrap_generic(ret_typ)).replace('*', '_ptr')
unwrapped_ret_typ := g.unwrap_generic(ret_typ)
styp = g.base_type(unwrapped_ret_typ)
ret_styp := g.typ(unwrapped_ret_typ).replace('*', '_ptr')
g.writeln('${ret_styp} ${tmp_var};')
} else {
g.writeln('${g.typ(ret_typ)} ${tmp_var};')
Expand Down

0 comments on commit 9e8a159

Please sign in to comment.