vfmt: fix error with `return // comment` (#6914)

pull/6918/head
Takahiro Yaota 2020-11-23 18:36:20 +09:00 committed by GitHub
parent 51c737669d
commit 2f9b7fe0f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 3 deletions

View File

@ -1,6 +1,6 @@
fn fun() int { fn fun() int {
// comment zero // comment zero
return 0 return 0 // another comment
} }
fn mr_fun() (int, int) { fn mr_fun() (int, int) {
@ -34,4 +34,6 @@ fn main() {
else { else {
println('else') println('else')
} }
// empty return
return
} }

View File

@ -1,5 +1,5 @@
fn fun() int { fn fun() int {
return /* comment zero */ 0 return /* comment zero */ 0 // another comment
} }
fn mr_fun() (int, int) { fn mr_fun() (int, int) {
@ -22,4 +22,5 @@ fn main() {
else /* after else */ { else /* after else */ {
println('else') println('else')
} }
return // empty return
} }

View File

@ -1737,13 +1737,16 @@ fn (mut p Parser) return_stmt() ast.Return {
first_pos := p.tok.position() first_pos := p.tok.position()
p.next() p.next()
// no return // no return
mut comments := p.eat_comments()
if p.tok.kind == .rcbr { if p.tok.kind == .rcbr {
return ast.Return{ return ast.Return{
comments: comments
pos: first_pos pos: first_pos
} }
} }
// return exprs // return exprs
exprs, comments := p.expr_list() exprs, comments2 := p.expr_list()
comments << comments2
end_pos := exprs.last().position() end_pos := exprs.last().position()
return ast.Return{ return ast.Return{
exprs: exprs exprs: exprs