Skip to content

Commit b0ea31e

Browse files
authored
cgen: fix alias indent (fix #26272) (#26333)
1 parent b5effad commit b0ea31e

4 files changed

Lines changed: 4 additions & 7 deletions

File tree

vlib/v/gen/c/auto_str_methods.v

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,20 +282,17 @@ fn (mut g Gen) gen_str_for_alias(info ast.Alias, styp string, str_fn_name string
282282
g.auto_str_funcs.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${arg_def}, ${ast.int_type_name} indent_count) {')
283283
old := g.reset_tmp_count()
284284
defer { g.tmp_count = old }
285-
g.auto_str_funcs.writeln('\tstring indents = builtin__string_repeat(_S(" "), indent_count);')
286285
if str_method_expects_ptr {
287286
it_arg := if is_c_struct { 'it' } else { '&it' }
288287
g.auto_str_funcs.writeln('\tstring tmp_ds = ${parent_str_fn_name}(${it_arg});')
289288
} else {
290289
deref, _ := deref_kind(str_method_expects_ptr, info.parent_type.is_ptr(), info.parent_type)
291290
g.auto_str_funcs.writeln('\tstring tmp_ds = ${parent_str_fn_name}(${deref}it);')
292291
}
293-
g.auto_str_funcs.writeln('\tstring res = builtin__str_intp(3, _MOV((StrIntpData[]){
294-
{_SLIT0, ${si_s_code}, {.d_s = indents }},
292+
g.auto_str_funcs.writeln('\tstring res = builtin__str_intp(2, _MOV((StrIntpData[]){
295293
{_S("${clean_type_v_type_name}("), ${si_s_code}, {.d_s = tmp_ds }},
296294
{_S(")"), 0, {.d_c = 0 }}
297295
}));')
298-
g.auto_str_funcs.writeln('\tbuiltin__string_free(&indents);')
299296
g.auto_str_funcs.writeln('\tbuiltin__string_free(&tmp_ds);')
300297
g.auto_str_funcs.writeln('\treturn res;')
301298
g.auto_str_funcs.writeln('}')

vlib/v/tests/aliases/alias_in_a_struct_field_autostr_test.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ fn test_string_interpolation_of_alias() {
88
x := Abc{
99
d: i64(9_123_456_789)
1010
}
11-
assert '${x}' == 'Abc{\n d: Duration(9123456789)\n}'
11+
assert '${x}' == 'Abc{\n d: Duration(9123456789)\n}'
1212
}

vlib/v/tests/comptime/comptime_var_param_test.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn test_main() {
1919
aa := Aa{}
2020

2121
assert encode_struct(aa) == 'Aa{
22-
sub: AliasType(Bb{
22+
sub: AliasType(Bb{
2323
a: 0
2424
})
2525
}'

vlib/v/tests/structs/struct_with_alias_embed_test.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ struct Bar {
88

99
fn test_main() {
1010
assert Bar{}.str() == 'Bar{
11-
Foo2: Foo2(Foo1{})
11+
Foo2: Foo2(Foo1{})
1212
}'
1313
}

0 commit comments

Comments
 (0)