File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -1639,7 +1639,8 @@ pub fn (mut f Fmt) if_expr(node ast.IfExpr) {
1639
1639
&& branch_is_single_line (node.branches[0 ]) && branch_is_single_line (node.branches[1 ])
1640
1640
&& (node.is_expr || f.is_assign || f.is_struct_init || f.single_line_fields)
1641
1641
f.single_line_if = single_line
1642
- if_start := f.line_len
1642
+ start_pos := f.out.len
1643
+ start_len := f.line_len
1643
1644
for {
1644
1645
for i, branch in node.branches {
1645
1646
if i == 0 {
@@ -1685,8 +1686,9 @@ pub fn (mut f Fmt) if_expr(node ast.IfExpr) {
1685
1686
if single_line && f.line_len > fmt.max_len.last () && ! f.buffering {
1686
1687
single_line = false
1687
1688
f.single_line_if = false
1688
- f.out.go_back (f.line_len - if_start)
1689
- f.line_len = if_start
1689
+ f.out.go_back_to (start_pos)
1690
+ f.line_len = start_len
1691
+ f.empty_line = start_len == 0
1690
1692
continue
1691
1693
}
1692
1694
break
Original file line number Diff line number Diff line change @@ -7,3 +7,14 @@ fn (f Foo) method_with_or() int {
7
7
f.fn_with_optional() or { return 10 }
8
8
return 20
9
9
}
10
+
11
+ fn unwrapped_single_line_if() {
12
+ namefound := publisher.name_fix_check(name_to_find, state.site.id, ispage) or {
13
+ if err.contains('Could not find') {
14
+ state.error('cannot find link: $name_to_find')
15
+ } else {
16
+ state.error('cannot find link: $name_to_find\n$err')
17
+ }
18
+ println('Another stmt')
19
+ }
20
+ }
You can’t perform that action at this time.
0 commit comments