Skip to content

Commit

Permalink
cgen: fix error of reference struct str() (#12061)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Oct 4, 2021
1 parent a8c2c41 commit 03269f9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions vlib/v/gen/c/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,10 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
// }
if !node.receiver_type.is_ptr() && node.left_type.is_ptr() && node.name == 'str' {
g.write('ptr_str(')
} else if node.receiver_type.is_ptr() && node.left_type.is_ptr() && node.name == 'str'
&& !left_sym.has_method('str') {
g.gen_expr_to_string(node.left, node.left_type)
return
} else {
if left_sym.kind == .array {
if array_depth >= 0 {
Expand Down
12 changes: 12 additions & 0 deletions vlib/v/tests/str_reference_struct_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
struct Example {
}

fn test_str_reference_struct() {
c1 := Example{}
println((&c1).str())
assert (&c1).str() == '&Example{}'

c2 := &Example{}
println(c2.str())
assert c2.str() == '&Example{}'
}

0 comments on commit 03269f9

Please sign in to comment.