Skip to content

Commit 7e27920

Browse files
author
Lukas Neubert
authored
fmt: fix inserted empty line before go stmt with anonymus function (#8951)
1 parent 12a4e7a commit 7e27920

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

vlib/v/ast/ast.v

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,12 +1340,9 @@ pub fn (stmt Stmt) position() token.Position {
13401340
match stmt {
13411341
AssertStmt, AssignStmt, Block, BranchStmt, CompFor, ConstDecl, DeferStmt, EnumDecl, ExprStmt,
13421342
FnDecl, ForCStmt, ForInStmt, ForStmt, GotoLabel, GotoStmt, Import, Return, StructDecl,
1343-
GlobalDecl, HashStmt, InterfaceDecl, Module, SqlStmt {
1343+
GlobalDecl, HashStmt, InterfaceDecl, Module, SqlStmt, GoStmt {
13441344
return stmt.pos
13451345
}
1346-
GoStmt {
1347-
return stmt.call_expr.pos
1348-
}
13491346
TypeDecl {
13501347
match stmt {
13511348
AliasTypeDecl, FnTypeDecl, SumTypeDecl { return stmt.pos }

vlib/v/fmt/fmt.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ pub fn (f Fmt) imp_stmt_str(imp ast.Import) string {
310310
return '$imp.mod$imp_alias_suffix'
311311
}
312312

313-
fn (mut f Fmt) should_insert_newline_before_stmt(stmt ast.Stmt, prev_stmt ast.Stmt) bool {
313+
fn (f Fmt) should_insert_newline_before_stmt(stmt ast.Stmt, prev_stmt ast.Stmt) bool {
314314
prev_line_nr := prev_stmt.position().last_line
315315
// No need to insert a newline if there is already one
316316
if f.out.last_n(2) == '\n\n' {

vlib/v/fmt/tests/go_stmt_keep.vv

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import sync
2+
3+
fn go_with_anon_fn() {
4+
wg.add(1)
5+
go fn (mut wg sync.WaitGroup) {
6+
wg.done()
7+
}(mut wg)
8+
wg.wait()
9+
}

vlib/v/parser/parser.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ pub fn (mut p Parser) stmt(is_top_level bool) ast.Stmt {
779779
}
780780
return ast.GoStmt{
781781
call_expr: call_expr
782-
pos: spos.extend(p.tok.position())
782+
pos: spos.extend(p.prev_tok.position())
783783
}
784784
}
785785
.key_goto {

0 commit comments

Comments
 (0)