diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index cc2f0d9ac3..f9177e7654 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -273,6 +273,7 @@ pub: pub mut: stmts []Stmt return_type table.Type + comments []Comment // comments *after* the header, but *before* `{`; used for InterfaceDecl } // break, continue diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index b7010c0fa5..a9a45de479 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -688,7 +688,13 @@ pub fn (mut f Fmt) interface_decl(node ast.InterfaceDecl) { f.comments_after_last_field(node.pre_comments) for method in node.methods { f.write('\t') - f.writeln(method.stringify(f.table, f.cur_mod).after('fn ')) + f.write(method.stringify(f.table, f.cur_mod).after('fn ')) + f.comments(method.comments, { + inline: true + has_nl: false + level: .indent + }) + f.writeln('') } f.writeln('}\n') } diff --git a/vlib/v/fmt/tests/interface_declaration_comments_keep.vv b/vlib/v/fmt/tests/interface_declaration_comments_keep.vv new file mode 100644 index 0000000000..d4404263db --- /dev/null +++ b/vlib/v/fmt/tests/interface_declaration_comments_keep.vv @@ -0,0 +1,4 @@ +pub interface ReaderWriter { + read(mut buf []byte) ?int // from Reader + write(buf []byte) ?int // from Writer +} diff --git a/vlib/v/parser/struct.v b/vlib/v/parser/struct.v index b71acaf934..0de2412c79 100644 --- a/vlib/v/parser/struct.v +++ b/vlib/v/parser/struct.v @@ -423,6 +423,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl { if p.tok.kind.is_start_of_type() && p.tok.line_nr == line_nr { method.return_type = p.parse_type() } + method.comments = p.eat_comments() methods << method // println('register method $name') return_type_sym := p.table.get_type_symbol(method.return_type)