Skip to content

Commit

Permalink
parser: fix formatting enum and interface decl with comments (#20216)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Dec 19, 2023
1 parent 17d540e commit d474f69
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 3 deletions.
4 changes: 4 additions & 0 deletions vlib/v/fmt/tests/enum_decl_with_comment_expected.vv
@@ -0,0 +1,4 @@
enum ABC { // enum ABC
// aaa
aaa
}
5 changes: 5 additions & 0 deletions vlib/v/fmt/tests/enum_decl_with_comment_input.vv
@@ -0,0 +1,5 @@
enum ABC // enum ABC
{
// aaa
aaa
}
4 changes: 4 additions & 0 deletions vlib/v/fmt/tests/interface_decl_with_comment_expected.vv
@@ -0,0 +1,4 @@
interface Abc { // interface Abc
a int
get_info() string
}
5 changes: 5 additions & 0 deletions vlib/v/fmt/tests/interface_decl_with_comment_input.vv
@@ -0,0 +1,5 @@
interface Abc // interface Abc
{
a int
get_info() string
}
3 changes: 2 additions & 1 deletion vlib/v/parser/parser.v
Expand Up @@ -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{}
Expand Down
4 changes: 2 additions & 2 deletions vlib/v/parser/struct.v
Expand Up @@ -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)
Expand Down

0 comments on commit d474f69

Please sign in to comment.