mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
This commit is contained in:
parent
42777f0125
commit
42ae1b3080
2 changed files with 23 additions and 1 deletions
|
@ -846,6 +846,21 @@ fn expr_is_single_line(expr ast.Expr) bool {
|
|||
ast.StringLiteral {
|
||||
return expr.pos.line_nr == expr.pos.last_line
|
||||
}
|
||||
ast.OrExpr {
|
||||
if expr.stmts.len == 1 && stmt_is_single_line(expr.stmts[0]) {
|
||||
stmt := expr.stmts[0]
|
||||
if stmt is ast.ExprStmt && stmt.expr is ast.CallExpr
|
||||
&& (stmt.expr as ast.CallExpr).comments.len > 0 {
|
||||
if comment := stmt.expr.comments[0] {
|
||||
if !comment.is_multi {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
else {}
|
||||
}
|
||||
return true
|
||||
|
@ -2923,7 +2938,7 @@ pub fn (mut f Fmt) or_expr(node ast.OrExpr) {
|
|||
}
|
||||
f.write('}')
|
||||
return
|
||||
} else if node.stmts.len == 1 && stmt_is_single_line(node.stmts[0]) {
|
||||
} else if expr_is_single_line(node) {
|
||||
// the control stmts (return/break/continue...) print a newline inside them,
|
||||
// so, since this'll all be on one line, trim any possible whitespace
|
||||
str := f.node_str(node.stmts[0]).trim_space()
|
||||
|
|
|
@ -99,3 +99,10 @@ fn ifs_comments_and_empty_lines() {
|
|||
// thereore keep the empty line
|
||||
something_else()
|
||||
}
|
||||
|
||||
fn call_expr_with_single_line_comment_in_or_expr(arr []int) int {
|
||||
i := arr[0] or {
|
||||
arr.count() // 1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue