mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser, fmt: fix the formatting of fn headers with inline comments (#14010)
This commit is contained in:
parent
07207db998
commit
3e3b2e25db
@ -953,8 +953,11 @@ fn (mut f Fmt) fn_body(node ast.FnDecl) {
|
||||
if node.language == .v {
|
||||
if !node.no_body {
|
||||
f.write(' {')
|
||||
f.comments(node.comments, inline: true)
|
||||
if node.stmts.len > 0 || node.pos.line_nr < node.pos.last_line {
|
||||
if node.comments.len == 0 {
|
||||
f.writeln('')
|
||||
}
|
||||
f.stmts(node.stmts)
|
||||
}
|
||||
f.write('}')
|
||||
|
@ -0,0 +1,7 @@
|
||||
fn main() { // main
|
||||
return
|
||||
}
|
||||
|
||||
fn print_hi() { // hi
|
||||
println('hi')
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
fn /*main*/main() {
|
||||
return
|
||||
}
|
||||
|
||||
fn // hi
|
||||
print_hi(){println('hi')}
|
@ -182,6 +182,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
||||
mut is_ctor_new := false
|
||||
mut is_c2v_variadic := false
|
||||
mut is_markused := false
|
||||
mut comments := []ast.Comment{}
|
||||
for fna in p.attrs {
|
||||
match fna.name {
|
||||
'noreturn' { is_noreturn = true }
|
||||
@ -205,6 +206,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
||||
p.next()
|
||||
}
|
||||
p.check(.key_fn)
|
||||
comments << p.eat_comments()
|
||||
p.open_scope()
|
||||
// C. || JS.
|
||||
mut language := ast.Language.v
|
||||
@ -530,6 +532,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
||||
scope: p.scope
|
||||
label_names: p.label_names
|
||||
end_comments: p.eat_comments(same_line: true)
|
||||
comments: comments
|
||||
}
|
||||
if generic_names.len > 0 {
|
||||
p.table.register_fn_generic_types(fn_decl.fkey())
|
||||
|
Loading…
Reference in New Issue
Block a user