cgen: skip deleted map entries in the auto generated .str() method
							parent
							
								
									a3404a38c6
								
							
						
					
					
						commit
						7feb1742d3
					
				|  | @ -339,3 +339,17 @@ fn test_mut_map_with_relation_op_in_fn() { | |||
| 	assert 'seven' in m | ||||
| 	assert 'eight' in m | ||||
| } | ||||
| 
 | ||||
| fn test_map_str_after_delete() { | ||||
| 	mut m := { | ||||
| 		'first': 1, | ||||
| 		'second': 2, | ||||
| 		'third': 3, | ||||
| 	} | ||||
| 	osm := '$m' | ||||
| 	m.delete('second') | ||||
| 	nsm := '$m' | ||||
|     println('m: $m') | ||||
| 	assert osm == "{'first': 1, 'second': 2, 'third': 3}" | ||||
| 	assert nsm == "{'first': 1, 'third': 3}" | ||||
| } | ||||
|  |  | |||
|  | @ -256,6 +256,7 @@ fn (mut g Gen) gen_str_for_map(info table.Map, styp string, str_fn_name string) | |||
| 	g.auto_str_funcs.writeln('\tstrings__Builder sb = strings__new_builder(m.key_values.len*10);') | ||||
| 	g.auto_str_funcs.writeln('\tstrings__Builder_write(&sb, tos_lit("{"));') | ||||
| 	g.auto_str_funcs.writeln('\tfor (unsigned int i = 0; i < m.key_values.len; ++i) {') | ||||
| 	g.auto_str_funcs.writeln('\t\tif (m.key_values.keys[i].str == 0) { continue; }') | ||||
| 	g.auto_str_funcs.writeln('\t\tstring key = (*(string*)DenseArray_get(m.key_values, i));') | ||||
| 	g.auto_str_funcs.writeln('\t\tstrings__Builder_write(&sb, _STR("\'%.*s\\000\'", 2, key));') | ||||
| 	g.auto_str_funcs.writeln('\t\tstrings__Builder_write(&sb, tos_lit(": "));') | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue