vfmt: keep `mut:` in interface declarations (#9053)
parent
c9a9f948be
commit
6da66226e5
|
@ -231,6 +231,7 @@ pub:
|
||||||
field_names []string
|
field_names []string
|
||||||
is_pub bool
|
is_pub bool
|
||||||
methods []FnDecl
|
methods []FnDecl
|
||||||
|
mut_pos int // mut:
|
||||||
fields []StructField
|
fields []StructField
|
||||||
pos token.Position
|
pos token.Position
|
||||||
pre_comments []Comment
|
pre_comments []Comment
|
||||||
|
|
|
@ -817,7 +817,10 @@ pub fn (mut f Fmt) interface_decl(node ast.InterfaceDecl) {
|
||||||
f.writeln('')
|
f.writeln('')
|
||||||
}
|
}
|
||||||
f.comments_after_last_field(node.pre_comments)
|
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.
|
// TODO: alignment, comments, etc.
|
||||||
mut ft := f.no_cur_mod(f.table.type_to_str(field.typ))
|
mut ft := f.no_cur_mod(f.table.type_to_str(field.typ))
|
||||||
if !ft.contains('C.') && !ft.contains('JS.') && !ft.contains('fn (') {
|
if !ft.contains('C.') && !ft.contains('JS.') && !ft.contains('fn (') {
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
interface Toto {
|
||||||
|
a int
|
||||||
|
mut:
|
||||||
|
b int
|
||||||
|
f()
|
||||||
|
}
|
|
@ -461,6 +461,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
|
||||||
mut fields := []ast.StructField{cap: 20}
|
mut fields := []ast.StructField{cap: 20}
|
||||||
mut methods := []ast.FnDecl{cap: 20}
|
mut methods := []ast.FnDecl{cap: 20}
|
||||||
mut is_mut := false
|
mut is_mut := false
|
||||||
|
mut mut_pos := -1
|
||||||
for p.tok.kind != .rcbr && p.tok.kind != .eof {
|
for p.tok.kind != .rcbr && p.tok.kind != .eof {
|
||||||
if p.tok.kind == .key_mut {
|
if p.tok.kind == .key_mut {
|
||||||
if is_mut {
|
if is_mut {
|
||||||
|
@ -470,6 +471,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
|
||||||
p.next()
|
p.next()
|
||||||
p.check(.colon)
|
p.check(.colon)
|
||||||
is_mut = true
|
is_mut = true
|
||||||
|
mut_pos = fields.len
|
||||||
}
|
}
|
||||||
if p.peek_tok.kind == .lpar {
|
if p.peek_tok.kind == .lpar {
|
||||||
method_start_pos := p.tok.position()
|
method_start_pos := p.tok.position()
|
||||||
|
@ -566,5 +568,6 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
|
||||||
is_pub: is_pub
|
is_pub: is_pub
|
||||||
pos: pos
|
pos: pos
|
||||||
pre_comments: pre_comments
|
pre_comments: pre_comments
|
||||||
|
mut_pos: mut_pos
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue