fmt: fix inserted empty line before go stmt with anonymus function (#8951)

pull/8938/head^2
Lukas Neubert 2021-02-25 01:30:04 +01:00 committed by GitHub
parent 12a4e7ad90
commit 7e27920cf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 6 deletions

View File

@ -1340,12 +1340,9 @@ pub fn (stmt Stmt) position() token.Position {
match stmt {
AssertStmt, AssignStmt, Block, BranchStmt, CompFor, ConstDecl, DeferStmt, EnumDecl, ExprStmt,
FnDecl, ForCStmt, ForInStmt, ForStmt, GotoLabel, GotoStmt, Import, Return, StructDecl,
GlobalDecl, HashStmt, InterfaceDecl, Module, SqlStmt {
GlobalDecl, HashStmt, InterfaceDecl, Module, SqlStmt, GoStmt {
return stmt.pos
}
GoStmt {
return stmt.call_expr.pos
}
TypeDecl {
match stmt {
AliasTypeDecl, FnTypeDecl, SumTypeDecl { return stmt.pos }

View File

@ -310,7 +310,7 @@ pub fn (f Fmt) imp_stmt_str(imp ast.Import) string {
return '$imp.mod$imp_alias_suffix'
}
fn (mut f Fmt) should_insert_newline_before_stmt(stmt ast.Stmt, prev_stmt ast.Stmt) bool {
fn (f Fmt) should_insert_newline_before_stmt(stmt ast.Stmt, prev_stmt ast.Stmt) bool {
prev_line_nr := prev_stmt.position().last_line
// No need to insert a newline if there is already one
if f.out.last_n(2) == '\n\n' {

View File

@ -0,0 +1,9 @@
import sync
fn go_with_anon_fn() {
wg.add(1)
go fn (mut wg sync.WaitGroup) {
wg.done()
}(mut wg)
wg.wait()
}

View File

@ -779,7 +779,7 @@ pub fn (mut p Parser) stmt(is_top_level bool) ast.Stmt {
}
return ast.GoStmt{
call_expr: call_expr
pos: spos.extend(p.tok.position())
pos: spos.extend(p.prev_tok.position())
}
}
.key_goto {