gen: struct str fixes (#6483)
							parent
							
								
									b999d01de7
								
							
						
					
					
						commit
						d782de5b00
					
				|  | @ -320,7 +320,10 @@ fn (mut g Gen) gen_str_for_struct(info table.Struct, styp, str_fn_name string) { | |||
| 	g.auto_str_funcs.writeln('\tfor (int i = 0; i < indent_count; ++i) {') | ||||
| 	g.auto_str_funcs.writeln('\t\tindents = string_add(indents, tos_lit("    "));') | ||||
| 	g.auto_str_funcs.writeln('\t}') | ||||
| 	g.auto_str_funcs.writeln('\treturn _STR("$clean_struct_v_type_name {\\n"') | ||||
| 	if info.fields.len == 0 { | ||||
| 		g.auto_str_funcs.write('\treturn tos_lit("$clean_struct_v_type_name { }");') | ||||
| 	} else { | ||||
| 		g.auto_str_funcs.write('\treturn _STR("$clean_struct_v_type_name {\\n"') | ||||
| 		for field in info.fields { | ||||
| 			mut fmt := g.type_to_fmt(field.typ) | ||||
| 			if field.typ.is_ptr() { | ||||
|  | @ -359,6 +362,7 @@ fn (mut g Gen) gen_str_for_struct(info table.Struct, styp, str_fn_name string) { | |||
| 		} | ||||
| 		g.auto_str_funcs.writeln(',') | ||||
| 		g.auto_str_funcs.writeln('\t\tindents);') | ||||
| 	} | ||||
| 	g.auto_str_funcs.writeln('}') | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -177,8 +177,8 @@ struct Wrapper4 { | |||
| fn test_struct_with_struct_pointer() { | ||||
| 	b := Foo{} | ||||
| 	w := Wrapper4{&b} | ||||
| 	assert '$w' == 'Wrapper4 {\n    foo: &Foo {\n    }\n}' | ||||
| 	assert w.str() == 'Wrapper4 {\n    foo: &Foo {\n    }\n}' | ||||
| 	assert '$w' == 'Wrapper4 {\n    foo: &Foo { }\n}' | ||||
| 	assert w.str() == 'Wrapper4 {\n    foo: &Foo { }\n}' | ||||
| } | ||||
| 
 | ||||
| fn test_struct_with_nil() { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue