Skip to content

Commit

Permalink
cgen: fix printing fn call of returning c struct value
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Dec 9, 2024
1 parent d257a1f commit 131ebd4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion vlib/v/gen/c/str.v
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype ast.Type) {
is_dump_expr := expr is ast.DumpExpr
is_var_mut := expr.is_auto_deref_var()
str_fn_name := g.get_str_fn(exp_typ)
temp_var_needed := expr is ast.CallExpr && expr.return_type.is_ptr()
temp_var_needed := expr is ast.CallExpr
&& (expr.return_type.is_ptr() || g.table.final_sym(expr.return_type).is_c_struct())
mut tmp_var := ''
if temp_var_needed {
tmp_var = g.new_tmp_var()
Expand Down
4 changes: 4 additions & 0 deletions vlib/v/tests/c_structs/csize.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
struct Size {
int width;
int height;
};
15 changes: 15 additions & 0 deletions vlib/v/tests/c_structs/return_csize_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "@VMODROOT/csize.h"

struct C.Size {
width int
height int
}

fn get_size() C.Size {
return C.Size{11, 22}
}

fn test_return_csize() {
println(get_size())
assert true
}

0 comments on commit 131ebd4

Please sign in to comment.