1
0
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:
yuyi 2021-10-04 14:58:50 +08:00 committed by GitHub
parent a8c2c419cd
commit 03269f9854
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -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 {

View 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{}'
}