Skip to content

Commit 4205697

Browse files
authored
fmt: fix if x := g() { x } else { return } adding newline after return (fix #24908) (#24945)
1 parent 5d4e89f commit 4205697

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

vlib/v/fmt/fmt.v

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1613,7 +1613,9 @@ pub fn (mut f Fmt) return_stmt(node ast.Return) {
16131613
}
16141614
}
16151615
}
1616-
f.writeln('')
1616+
if !f.single_line_if {
1617+
f.writeln('')
1618+
}
16171619
}
16181620

16191621
pub fn (mut f Fmt) sql_stmt(node ast.SqlStmt) {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module main
2+
3+
fn g() ?int {
4+
return 123
5+
}
6+
7+
x := if ff := g() { ff } else { return }
8+
println(x)

vlib/v/tests/fns/closure_test.v

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,7 @@ fn test_go_call_closure() {
155155
fn test_closures_with_ifstmt() {
156156
a := 1
157157
f := fn [a] (x int) int {
158-
if a > x { return 1
159-
} else { return -1
160-
}
158+
if a > x { return 1 } else { return -1 }
161159
}
162160
g := fn [a] () int {
163161
if true {

0 commit comments

Comments
 (0)