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:
parent
de0683fe30
commit
5464de406c
@ -106,7 +106,7 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype ast.Type) {
|
|||||||
g.write('${str_fn_name}(')
|
g.write('${str_fn_name}(')
|
||||||
if str_method_expects_ptr && !is_ptr {
|
if str_method_expects_ptr && !is_ptr {
|
||||||
g.write('&')
|
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('*')
|
g.write('*')
|
||||||
}
|
}
|
||||||
if expr is ast.ArrayInit {
|
if expr is ast.ArrayInit {
|
||||||
|
@ -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'
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user