diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index 1f5de9d754..9720be1f77 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -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 } diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 48cf28299e..d260a202c7 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -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' { diff --git a/vlib/v/fmt/tests/go_stmt_keep.vv b/vlib/v/fmt/tests/go_stmt_keep.vv new file mode 100644 index 0000000000..e4041567cf --- /dev/null +++ b/vlib/v/fmt/tests/go_stmt_keep.vv @@ -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() +} diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index cde33d4978..3cd479db7e 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -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 {