diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 642b6a7479..7356e349db 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -912,7 +912,7 @@ pub fn (c mut Checker) if_expr(node mut ast.IfExpr) table.Type { node.typ = table.void_type for i, branch in node.branches { typ := c.expr(branch.cond) - if i < node.branches.len-1 || !node.has_else { + if i < node.branches.len - 1 || !node.has_else { typ_sym := c.table.get_type_symbol(typ) // if typ_sym.kind != .bool { if table.type_idx(typ) != table.bool_type_idx { @@ -922,7 +922,7 @@ pub fn (c mut Checker) if_expr(node mut ast.IfExpr) table.Type { c.stmts(branch.stmts) } if node.has_else && node.is_expr { - last_branch := node.branches[node.branches.len-1] + last_branch := node.branches[node.branches.len - 1] if last_branch.stmts.len > 0 { match last_branch.stmts[last_branch.stmts.len - 1] { ast.ExprStmt { @@ -933,7 +933,7 @@ pub fn (c mut Checker) if_expr(node mut ast.IfExpr) table.Type { return t } else {} - } + } } } return table.bool_type diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 0f81ff4ae0..e72020c521 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -406,9 +406,6 @@ fn (f mut Fmt) expr(node ast.Expr) { f.write(' ') } } - // if !single_line { - // f.writeln('') - // } f.write('}') f.single_line_if = false } diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index ead5c1dd7f..689b0fd8dc 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -1176,14 +1176,14 @@ fn (g mut Gen) if_expr(node ast.IfExpr) { } // one line ?: // TODO clean this up once `is` is supported - // TODO: make sure only one stmt in eac branch + // TODO: make sure only one stmt in each branch if node.is_expr && node.branches.len >= 2 && node.has_else && type_sym.kind != .void { g.inside_ternary = true for i, branch in node.branches { if i > 0 { g.write(' : ') } - if i < node.branches.len-1 || !node.has_else { + if i < node.branches.len - 1 || !node.has_else { g.expr(branch.cond) g.write(' ? ') } @@ -1210,15 +1210,14 @@ fn (g mut Gen) if_expr(node ast.IfExpr) { g.expr(branch.cond) g.writeln(') {') } - } - + } } - else if i < node.branches.len-1 || !node.has_else { + else if i < node.branches.len - 1 || !node.has_else { g.writeln('} else if (') g.expr(branch.cond) g.write(') {') } - else if i == node.branches.len-1 && node.has_else { + else if i == node.branches.len - 1 && node.has_else { if is_guard { g.writeln('} if (!$guard_ok) { /* else */') } @@ -1229,9 +1228,7 @@ fn (g mut Gen) if_expr(node ast.IfExpr) { // Assign ret value // if i == node.stmts.len - 1 && type_sym.kind != .void {} // g.writeln('$tmp =') - // g.stmts(branch.stmts) - // g.writeln('') } if is_guard { g.write('}')