From b0ea31e90d145fead68fc62625b5b40c060937f3 Mon Sep 17 00:00:00 2001 From: kbkpbot Date: Tue, 13 Jan 2026 11:01:11 +0800 Subject: [PATCH] cgen: fix alias indent (fix #26272) (#26333) --- vlib/v/gen/c/auto_str_methods.v | 5 +---- vlib/v/tests/aliases/alias_in_a_struct_field_autostr_test.v | 2 +- vlib/v/tests/comptime/comptime_var_param_test.v | 2 +- vlib/v/tests/structs/struct_with_alias_embed_test.v | 2 +- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/vlib/v/gen/c/auto_str_methods.v b/vlib/v/gen/c/auto_str_methods.v index dc0d7eedb..9753464af 100644 --- a/vlib/v/gen/c/auto_str_methods.v +++ b/vlib/v/gen/c/auto_str_methods.v @@ -282,7 +282,6 @@ fn (mut g Gen) gen_str_for_alias(info ast.Alias, styp string, str_fn_name string g.auto_str_funcs.writeln('${g.static_non_parallel}string indent_${str_fn_name}(${arg_def}, ${ast.int_type_name} indent_count) {') old := g.reset_tmp_count() defer { g.tmp_count = old } - g.auto_str_funcs.writeln('\tstring indents = builtin__string_repeat(_S(" "), indent_count);') if str_method_expects_ptr { it_arg := if is_c_struct { 'it' } else { '&it' } g.auto_str_funcs.writeln('\tstring tmp_ds = ${parent_str_fn_name}(${it_arg});') @@ -290,12 +289,10 @@ fn (mut g Gen) gen_str_for_alias(info ast.Alias, styp string, str_fn_name string deref, _ := deref_kind(str_method_expects_ptr, info.parent_type.is_ptr(), info.parent_type) g.auto_str_funcs.writeln('\tstring tmp_ds = ${parent_str_fn_name}(${deref}it);') } - g.auto_str_funcs.writeln('\tstring res = builtin__str_intp(3, _MOV((StrIntpData[]){ - {_SLIT0, ${si_s_code}, {.d_s = indents }}, + g.auto_str_funcs.writeln('\tstring res = builtin__str_intp(2, _MOV((StrIntpData[]){ {_S("${clean_type_v_type_name}("), ${si_s_code}, {.d_s = tmp_ds }}, {_S(")"), 0, {.d_c = 0 }} }));') - g.auto_str_funcs.writeln('\tbuiltin__string_free(&indents);') g.auto_str_funcs.writeln('\tbuiltin__string_free(&tmp_ds);') g.auto_str_funcs.writeln('\treturn res;') g.auto_str_funcs.writeln('}') diff --git a/vlib/v/tests/aliases/alias_in_a_struct_field_autostr_test.v b/vlib/v/tests/aliases/alias_in_a_struct_field_autostr_test.v index 5e901f54f..acd4317dc 100644 --- a/vlib/v/tests/aliases/alias_in_a_struct_field_autostr_test.v +++ b/vlib/v/tests/aliases/alias_in_a_struct_field_autostr_test.v @@ -8,5 +8,5 @@ fn test_string_interpolation_of_alias() { x := Abc{ d: i64(9_123_456_789) } - assert '${x}' == 'Abc{\n d: Duration(9123456789)\n}' + assert '${x}' == 'Abc{\n d: Duration(9123456789)\n}' } diff --git a/vlib/v/tests/comptime/comptime_var_param_test.v b/vlib/v/tests/comptime/comptime_var_param_test.v index fba0c375b..6f6ff6a95 100644 --- a/vlib/v/tests/comptime/comptime_var_param_test.v +++ b/vlib/v/tests/comptime/comptime_var_param_test.v @@ -19,7 +19,7 @@ fn test_main() { aa := Aa{} assert encode_struct(aa) == 'Aa{ - sub: AliasType(Bb{ + sub: AliasType(Bb{ a: 0 }) }' diff --git a/vlib/v/tests/structs/struct_with_alias_embed_test.v b/vlib/v/tests/structs/struct_with_alias_embed_test.v index 3833c740f..5d82dcba2 100644 --- a/vlib/v/tests/structs/struct_with_alias_embed_test.v +++ b/vlib/v/tests/structs/struct_with_alias_embed_test.v @@ -8,6 +8,6 @@ struct Bar { fn test_main() { assert Bar{}.str() == 'Bar{ - Foo2: Foo2(Foo1{}) + Foo2: Foo2(Foo1{}) }' } -- 2.39.5