vfmt: keep `mut:` in interface declarations (#9053)

pull/9112/head
Delyan Angelov 2021-03-04 15:30:30 +02:00 committed by GitHub
parent c9a9f948be
commit 6da66226e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 1 deletions

View File

@ -231,6 +231,7 @@ pub:
field_names []string
is_pub bool
methods []FnDecl
mut_pos int // mut:
fields []StructField
pos token.Position
pre_comments []Comment

View File

@ -817,7 +817,10 @@ pub fn (mut f Fmt) interface_decl(node ast.InterfaceDecl) {
f.writeln('')
}
f.comments_after_last_field(node.pre_comments)
for field in node.fields {
for i, field in node.fields {
if i == node.mut_pos {
f.writeln('mut:')
}
// TODO: alignment, comments, etc.
mut ft := f.no_cur_mod(f.table.type_to_str(field.typ))
if !ft.contains('C.') && !ft.contains('JS.') && !ft.contains('fn (') {

View File

@ -0,0 +1,6 @@
interface Toto {
a int
mut:
b int
f()
}

View File

@ -461,6 +461,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
mut fields := []ast.StructField{cap: 20}
mut methods := []ast.FnDecl{cap: 20}
mut is_mut := false
mut mut_pos := -1
for p.tok.kind != .rcbr && p.tok.kind != .eof {
if p.tok.kind == .key_mut {
if is_mut {
@ -470,6 +471,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
p.next()
p.check(.colon)
is_mut = true
mut_pos = fields.len
}
if p.peek_tok.kind == .lpar {
method_start_pos := p.tok.position()
@ -566,5 +568,6 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
is_pub: is_pub
pos: pos
pre_comments: pre_comments
mut_pos: mut_pos
}
}