From 5440657364e7b3d95de3f0f940cb274422a89a3c Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sun, 4 Jun 2023 20:53:17 -0300 Subject: [PATCH] fmt: fix alias type stripped comments (#18346) --- vlib/v/fmt/tests/type_decl_comments_keep.vv | 4 ++++ vlib/v/parser/parser.v | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 vlib/v/fmt/tests/type_decl_comments_keep.vv diff --git a/vlib/v/fmt/tests/type_decl_comments_keep.vv b/vlib/v/fmt/tests/type_decl_comments_keep.vv new file mode 100644 index 0000000000..c52b3de35b --- /dev/null +++ b/vlib/v/fmt/tests/type_decl_comments_keep.vv @@ -0,0 +1,4 @@ +const a = 1 // foo + +pub type Keycode = int // foo +type Keycode2 = f64 | int // foo diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index af9bc1f1fc..51226fbf26 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -4118,7 +4118,7 @@ fn (mut p Parser) type_decl() ast.TypeDecl { p.error_with_pos('a type alias can not refer to itself: ${name}', decl_pos.extend(type_alias_pos)) return ast.AliasTypeDecl{} } - comments = p.eat_comments(same_line: true) + comments = sum_variants[0].end_comments.clone() return ast.AliasTypeDecl{ name: name is_pub: is_pub