cgen: use heuristic to detect circular reference in auto str (#11090)
							parent
							
								
									7d3476cbca
								
							
						
					
					
						commit
						c560d58f1e
					
				| 
						 | 
				
			
			@ -834,6 +834,9 @@ fn (mut g Gen) gen_str_for_struct(info ast.Struct, styp string, str_fn_name stri
 | 
			
		|||
			if field.typ in ast.charptr_types {
 | 
			
		||||
				fn_builder.write_string('tos2((byteptr)$func)')
 | 
			
		||||
			} else {
 | 
			
		||||
				if field.typ.is_ptr() && sym.kind == .struct_ {
 | 
			
		||||
					fn_builder.write_string('(indent_count > 25) ? _SLIT("<probably circular>") : ')
 | 
			
		||||
				}
 | 
			
		||||
				fn_builder.write_string(func)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,21 @@
 | 
			
		|||
[heap]
 | 
			
		||||
struct Aa {
 | 
			
		||||
mut:
 | 
			
		||||
	bs []Bb
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct Bb {
 | 
			
		||||
mut:
 | 
			
		||||
	a &Aa
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn test_circular() {
 | 
			
		||||
	mut b := Bb{
 | 
			
		||||
		a: &Aa{
 | 
			
		||||
			bs: []Bb{cap: 1}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	b.a.bs << b
 | 
			
		||||
	s := b.str()
 | 
			
		||||
	assert s.len < 3500
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue