From 1f21053bc0bb7bdc58eba65c7365af0e5249acd3 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 11 Mar 2026 12:40:26 +0300 Subject: [PATCH] vfmt: Array initializers should be indented (fixes #24091) --- vlib/v/fmt/struct.v | 4 +++- vlib/v/fmt/tests/array_init_expected.vv | 17 +++++++++++++++++ vlib/v/fmt/tests/array_init_input.vv | 17 +++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/vlib/v/fmt/struct.v b/vlib/v/fmt/struct.v index 5080a4495..032590c60 100644 --- a/vlib/v/fmt/struct.v +++ b/vlib/v/fmt/struct.v @@ -103,7 +103,9 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl, is_anon bool) { if field.has_default_expr { f.write(' '.repeat(default_expr_align.max_len(field.pos.line_nr) - field_types[i].len)) f.write(' = ') - if !expr_is_single_line(field.default_expr) { + default_expr_pos := field.default_expr.pos() + if default_expr_pos.line_nr < default_expr_pos.last_line + || !expr_is_single_line(field.default_expr) { f.indent++ inc_indent = true } diff --git a/vlib/v/fmt/tests/array_init_expected.vv b/vlib/v/fmt/tests/array_init_expected.vv index 90979c7d4..55b325c86 100644 --- a/vlib/v/fmt/tests/array_init_expected.vv +++ b/vlib/v/fmt/tests/array_init_expected.vv @@ -39,3 +39,20 @@ fn array_init_without_commas() { ch := chan u16{} w := [f, 12 <- ch] } + +struct App { +mut: + text string + result f64 + is_float bool + new_number bool + operands []f64 + operations []string + row_ops [][]string = [ + ['C', '%', '^', '/'], + ['7', '8', '9', '*'], + ['4', '5', '6', '-'], + ['1', '2', '3', '+'], + ['0', '.', '+/-', '='], + ] +} diff --git a/vlib/v/fmt/tests/array_init_input.vv b/vlib/v/fmt/tests/array_init_input.vv index 7d33d48f9..ef1825af0 100644 --- a/vlib/v/fmt/tests/array_init_input.vv +++ b/vlib/v/fmt/tests/array_init_input.vv @@ -33,3 +33,20 @@ fn array_init_without_commas() { ch := chan u16{} w := [f 12 <-ch] } + +struct App { +mut: + text string + result f64 + is_float bool + new_number bool + operands []f64 + operations []string + row_ops [][]string = [ + ['C', '%', '^', '/'], + ['7', '8', '9', '*'], + ['4', '5', '6', '-'], + ['1', '2', '3', '+'], + ['0', '.', '+/-', '='], + ] +} -- 2.39.5