1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix custom str on struct with too many fields (#15195)

This commit is contained in:
yuyi 2022-07-24 15:15:22 +08:00 committed by GitHub
parent de0683fe30
commit 5464de406c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View File

@ -106,7 +106,7 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype ast.Type) {
g.write('${str_fn_name}(')
if str_method_expects_ptr && !is_ptr {
g.write('&')
} else if (!str_method_expects_ptr && is_ptr && !is_shared) || is_var_mut {
} else if !str_method_expects_ptr && !is_shared && (is_ptr || is_var_mut) {
g.write('*')
}
if expr is ast.ArrayInit {

View File

@ -0,0 +1,29 @@
struct Abc {
a string
b string
c string
d string
//
e string
f string
g string
h string
//
x int // number of fields must be > 8
}
fn (a Abc) str() string {
return 'abc'
}
fn (a Abc) some_method() string {
println(a)
return '$a'
}
fn test_custom_str_on_struct_with_too_many_fields() {
abc := Abc{}
ret := abc.some_method()
println(ret)
assert ret == 'abc'
}