mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix error of reference struct str() (#12061)
This commit is contained in:
parent
a8c2c419cd
commit
03269f9854
@ -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 {
|
||||
|
12
vlib/v/tests/str_reference_struct_test.v
Normal file
12
vlib/v/tests/str_reference_struct_test.v
Normal file
@ -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{}'
|
||||
}
|
Loading…
Reference in New Issue
Block a user