mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
parent
6a60db8768
commit
4e498b4303
@ -969,9 +969,21 @@ fn (mut g Gen) gen_str_for_struct(info ast.Struct, styp string, typ_str string,
|
||||
funcprefix += '*'
|
||||
}
|
||||
}
|
||||
mut is_field_array := false
|
||||
if sym.info is ast.Array {
|
||||
field_styp = g.typ(sym.info.elem_type).trim('*')
|
||||
is_field_array = true
|
||||
} else if sym.info is ast.ArrayFixed {
|
||||
field_styp = g.typ(sym.info.elem_type).trim('*')
|
||||
is_field_array = true
|
||||
}
|
||||
// handle circular ref type of struct to the struct itself
|
||||
if styp == field_styp && !allow_circular {
|
||||
fn_body.write_string('${funcprefix}_SLIT("<circular>")')
|
||||
if is_field_array {
|
||||
fn_body.write_string('it.${c_name(field.name)}.len > 0 ? ${funcprefix}_SLIT("[<circular>]") : ${funcprefix}_SLIT("[]")')
|
||||
} else {
|
||||
fn_body.write_string('${funcprefix}_SLIT("<circular>")')
|
||||
}
|
||||
} else {
|
||||
// manage C charptr
|
||||
if field.typ in ast.charptr_types {
|
||||
|
@ -0,0 +1,5 @@
|
||||
&Person{
|
||||
name: 'John'
|
||||
relatives: [<circular>]
|
||||
}
|
||||
Success
|
@ -0,0 +1,18 @@
|
||||
struct Person {
|
||||
name string
|
||||
mut:
|
||||
relatives []&Person
|
||||
}
|
||||
|
||||
fn main() {
|
||||
mut father := &Person{
|
||||
name: 'John'
|
||||
}
|
||||
mut mother := &Person{
|
||||
name: 'Jane'
|
||||
relatives: [father]
|
||||
}
|
||||
father.relatives = [mother]
|
||||
println(father)
|
||||
println('Success')
|
||||
}
|
Loading…
Reference in New Issue
Block a user