mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: add &
before ptr arr elements (#17379)
This commit is contained in:
parent
6682911bc3
commit
c173104295
@ -558,7 +558,13 @@ fn (mut g Gen) gen_str_for_array(info ast.Array, styp string, str_fn_name string
|
||||
}
|
||||
if should_use_indent_func(sym.kind) && !sym_has_str_method {
|
||||
if is_elem_ptr {
|
||||
g.auto_str_funcs.writeln('\t\tstring x = indent_${elem_str_fn_name}(*it, indent_count);')
|
||||
deref, deref_label := deref_kind(str_method_expects_ptr, is_elem_ptr,
|
||||
typ)
|
||||
g.auto_str_funcs.writeln('\t\tstring x = _SLIT("nil");')
|
||||
g.auto_str_funcs.writeln('\t\tif (it != 0) {')
|
||||
g.auto_str_funcs.writeln('\t\t\tstrings__Builder_write_string(&sb, _SLIT("${deref_label}"));')
|
||||
g.auto_str_funcs.writeln('\t\t\tx = ${elem_str_fn_name}(${deref}it);')
|
||||
g.auto_str_funcs.writeln('\t\t}')
|
||||
} else {
|
||||
g.auto_str_funcs.writeln('\t\tstring x = indent_${elem_str_fn_name}(it, indent_count);')
|
||||
}
|
||||
|
@ -53,8 +53,8 @@ StructOfFixedArraysOfListeners{
|
||||
[&0, &0]
|
||||
[&&0, &&0]
|
||||
-----------------------------------------------------
|
||||
[EventListener{
|
||||
[&EventListener{
|
||||
x: 123
|
||||
}, EventListener{
|
||||
}, &EventListener{
|
||||
x: 0
|
||||
}]
|
||||
|
22
vlib/v/tests/array_of_ptrs_test.v
Normal file
22
vlib/v/tests/array_of_ptrs_test.v
Normal file
@ -0,0 +1,22 @@
|
||||
struct Point {
|
||||
x int
|
||||
y int
|
||||
}
|
||||
|
||||
fn test_array_of_ptr_str() {
|
||||
point_1 := &Point{1, 2}
|
||||
point_2 := &Point{3, 4}
|
||||
point_3 := &Point{5, 6}
|
||||
points := [point_1, point_2, point_3]
|
||||
assert '${points}' == '[&Point{
|
||||
x: 1
|
||||
y: 2
|
||||
}, &Point{
|
||||
x: 3
|
||||
y: 4
|
||||
}, &Point{
|
||||
x: 5
|
||||
y: 6
|
||||
}]
|
||||
'.trim_indent()
|
||||
}
|
Loading…
Reference in New Issue
Block a user