From 4718a818b8c72975e086088909495e0aaab5a42a Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 28 Dec 2022 18:06:32 +0200 Subject: [PATCH] =?UTF-8?q?vfmt:=20fix=20alignment=20of=20value=20formatti?= =?UTF-8?q?ng=20for=20"x=20:=3D=20{`.`:=201,=20`=E2=99=96`:=202}"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vlib/v/fmt/fmt.v | 8 +++-- ...rings_to_enums_init_with_utf8_keys_keep.vv | 35 +++++++++++++++++++ vlib/v/parser/parse_type.v | 7 ++-- 3 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 vlib/v/fmt/tests/map_of_strings_to_enums_init_with_utf8_keys_keep.vv diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index eca38a761..6edefd15f 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -2326,15 +2326,17 @@ pub fn (mut f Fmt) map_init(node ast.MapInit) { for key in node.keys { skey := f.node_str(key).trim_space() skeys << skey - if skey.len > max_field_len { - max_field_len = skey.len + skey_len := skey.len_utf8() + if skey_len > max_field_len { + max_field_len = skey_len } } for i, _ in node.keys { skey := skeys[i] f.write(skey) f.write(': ') - f.write(strings.repeat(` `, max_field_len - skey.len)) + skey_len := skey.len_utf8() + f.write(strings.repeat(` `, max_field_len - skey_len)) f.expr(node.vals[i]) f.comments(node.comments[i], prev_line: node.vals[i].pos().last_line, has_nl: false) f.writeln('') diff --git a/vlib/v/fmt/tests/map_of_strings_to_enums_init_with_utf8_keys_keep.vv b/vlib/v/fmt/tests/map_of_strings_to_enums_init_with_utf8_keys_keep.vv new file mode 100644 index 000000000..59326ab83 --- /dev/null +++ b/vlib/v/fmt/tests/map_of_strings_to_enums_init_with_utf8_keys_keep.vv @@ -0,0 +1,35 @@ +enum Pieces { + empty + off + wp + wn + wb + wr + wq + wk + bp + bn + bb + br + bq + bk +} + +const unicode_piece_map = { + `.`: Pieces.empty + `♙`: Pieces.wp + `♘`: Pieces.wn + `♗`: Pieces.wb + `♖`: Pieces.wr + `♕`: Pieces.wq + `♔`: Pieces.wk + `♟`: Pieces.bp + `♞`: Pieces.bn + `♝`: Pieces.bb + `♜`: Pieces.br + `♛`: Pieces.bq + `♚`: Pieces.bk + `o`: Pieces.off +} + +dump(unicode_piece_map) diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v index 53138e905..650ca61b3 100644 --- a/vlib/v/parser/parse_type.v +++ b/vlib/v/parser/parse_type.v @@ -305,8 +305,11 @@ pub fn (mut p Parser) parse_language() ast.Language { // parse_inline_sum_type parses the type and registers it in case the type is an anonymous sum type. // It also takes care of inline sum types where parse_type only parses a standalone type. pub fn (mut p Parser) parse_inline_sum_type() ast.Type { - p.warn('inline sum types have been deprecated and will be removed on January 1, 2023 due ' + - 'to complicating the language and the compiler too much; define named sum types with `type Foo = Bar | Baz` instead') + if !p.pref.is_fmt { + p.warn( + 'inline sum types have been deprecated and will be removed on January 1, 2023 due ' + + 'to complicating the language and the compiler too much; define named sum types with `type Foo = Bar | Baz` instead') + } variants := p.parse_sum_type_variants() if variants.len > 1 { if variants.len > parser.maximum_inline_sum_type_variants { -- 2.39.5