diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index cf365e3c4f..865c5e4ed9 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -3497,7 +3497,7 @@ pub fn (mut c Checker) lock_expr(mut node ast.LockExpr) ast.Type { // handle `x := rlock a { a.getval() }` mut ret_type := ast.void_type if node.stmts.len > 0 { - last_stmt := node.stmts[node.stmts.len - 1] + last_stmt := node.stmts.last() if last_stmt is ast.ExprStmt { ret_type = last_stmt.typ } diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 2f3dd00789..1ac5c9719c 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -302,7 +302,7 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) { // c.table.cur_fn = node // Add return if `fn(...) ? {...}` have no return at end if node.return_type != ast.void_type && node.return_type.has_flag(.optional) - && (node.stmts.len == 0 || node.stmts[node.stmts.len - 1] !is ast.Return) { + && (node.stmts.len == 0 || node.stmts.last() !is ast.Return) { sym := c.table.sym(node.return_type) if sym.kind == .void { node.stmts << ast.Return{ diff --git a/vlib/v/checker/if.v b/vlib/v/checker/if.v index eb4c8e72ec..5f813803a6 100644 --- a/vlib/v/checker/if.v +++ b/vlib/v/checker/if.v @@ -11,8 +11,8 @@ pub fn (mut c Checker) if_expr(mut node ast.IfExpr) ast.Type { mut node_is_expr := false if node.branches.len > 0 && node.has_else { stmts := node.branches[0].stmts - if stmts.len > 0 && stmts[stmts.len - 1] is ast.ExprStmt - && (stmts[stmts.len - 1] as ast.ExprStmt).typ != ast.void_type { + if stmts.len > 0 && stmts.last() is ast.ExprStmt + && (stmts.last() as ast.ExprStmt).typ != ast.void_type { node_is_expr = true } } diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index aa6516e87d..f3f740dcdd 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -4943,8 +4943,8 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type ast.Ty g.inside_or_block = false } stmts := or_block.stmts - if stmts.len > 0 && stmts[or_block.stmts.len - 1] is ast.ExprStmt - && (stmts[stmts.len - 1] as ast.ExprStmt).typ != ast.void_type { + if stmts.len > 0 && stmts.last() is ast.ExprStmt + && (stmts.last() as ast.ExprStmt).typ != ast.void_type { g.indent++ for i, stmt in stmts { if i == stmts.len - 1 { @@ -4966,7 +4966,7 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type ast.Ty g.indent-- } else { g.stmts(stmts) - if stmts.len > 0 && stmts[or_block.stmts.len - 1] is ast.ExprStmt { + if stmts.len > 0 && stmts.last() is ast.ExprStmt { g.writeln(';') } }