diff --git a/vlib/v/fmt/tests/enum_decl_with_comment_expected.vv b/vlib/v/fmt/tests/enum_decl_with_comment_expected.vv new file mode 100644 index 00000000000000..a00e34a3ae778d --- /dev/null +++ b/vlib/v/fmt/tests/enum_decl_with_comment_expected.vv @@ -0,0 +1,4 @@ +enum ABC { // enum ABC + // aaa + aaa +} diff --git a/vlib/v/fmt/tests/enum_decl_with_comment_input.vv b/vlib/v/fmt/tests/enum_decl_with_comment_input.vv new file mode 100644 index 00000000000000..abf424cdf9ab3c --- /dev/null +++ b/vlib/v/fmt/tests/enum_decl_with_comment_input.vv @@ -0,0 +1,5 @@ +enum ABC // enum ABC +{ + // aaa + aaa +} diff --git a/vlib/v/fmt/tests/interface_decl_with_comment_expected.vv b/vlib/v/fmt/tests/interface_decl_with_comment_expected.vv new file mode 100644 index 00000000000000..0d0717a143d2df --- /dev/null +++ b/vlib/v/fmt/tests/interface_decl_with_comment_expected.vv @@ -0,0 +1,4 @@ +interface Abc { // interface Abc + a int + get_info() string +} diff --git a/vlib/v/fmt/tests/interface_decl_with_comment_input.vv b/vlib/v/fmt/tests/interface_decl_with_comment_input.vv new file mode 100644 index 00000000000000..5d2e58be290954 --- /dev/null +++ b/vlib/v/fmt/tests/interface_decl_with_comment_input.vv @@ -0,0 +1,5 @@ +interface Abc // interface Abc +{ + a int + get_info() string +} diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 71384ffd73b1cb..cc907b451cf00a 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -4059,8 +4059,9 @@ fn (mut p Parser) enum_decl() ast.EnumDecl { typ_pos = p.tok.pos() enum_type = p.parse_type() } + mut enum_decl_comments := p.eat_comments() p.check(.lcbr) - enum_decl_comments := p.eat_comments() + enum_decl_comments << p.eat_comments() senum_type := p.table.get_type_name(enum_type) mut vals := []string{} // mut default_exprs := []ast.Expr{} diff --git a/vlib/v/parser/struct.v b/vlib/v/parser/struct.v index 999312c3fda56a..9748de70fd3854 100644 --- a/vlib/v/parser/struct.v +++ b/vlib/v/parser/struct.v @@ -533,9 +533,9 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl { interface_name = p.prepend_mod(modless_name) } generic_types, _ := p.parse_generic_types() - // println('interface decl $interface_name') + mut pre_comments := p.eat_comments() p.check(.lcbr) - pre_comments := p.eat_comments() + pre_comments << p.eat_comments() if modless_name in p.imported_symbols { p.error_with_pos('cannot register interface `${interface_name}`, this type was already imported', name_pos)