Skip to content

Commit

Permalink
parser: fix block position's last line (vlang#22913)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 authored Nov 19, 2024
1 parent db6ac0c commit 67d53aa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
7 changes: 0 additions & 7 deletions vlib/v/fmt/fmt.v
Original file line number Diff line number Diff line change
Expand Up @@ -443,13 +443,6 @@ fn (f &Fmt) should_insert_newline_before_node(node ast.Node, prev_node ast.Node)
ast.Import {
return false
}
ast.Block {
if node is ast.Block && !node.is_unsafe && node.pos.line_nr - prev_line_nr > 0 {
return true
} else {
return false
}
}
ast.ConstDecl {
if node !is ast.ConstDecl && !(node is ast.ExprStmt && node.expr is ast.Comment) {
return true
Expand Down
8 changes: 8 additions & 0 deletions vlib/v/fmt/tests/block_with_blank_line_keep.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn main() {
{
println('(1/3) My first small scope')
//
}

println('hello')
}
2 changes: 1 addition & 1 deletion vlib/v/parser/parser.v
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ fn (mut p Parser) stmt(is_top_level bool) ast.Stmt {
}
} else {
stmts := p.parse_block()
pos.last_line = p.prev_tok.line_nr
pos.update_last_line(p.prev_tok.line_nr)
return ast.Block{
stmts: stmts
pos: pos
Expand Down

0 comments on commit 67d53aa

Please sign in to comment.