diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 1617b46e08..8c80540a63 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -996,8 +996,8 @@ pub fn (mut c Checker) check_or_expr(node ast.OrExpr, ret_type ast.Type, expr_re } return } - stmts_len := node.stmts.len - if stmts_len == 0 { + + if node.stmts.len == 0 { if ret_type != ast.void_type { // x := f() or {} c.error('assignment requires a non empty `or {}` block', node.pos) @@ -1005,7 +1005,7 @@ pub fn (mut c Checker) check_or_expr(node ast.OrExpr, ret_type ast.Type, expr_re // allow `f() or {}` return } - last_stmt := node.stmts[stmts_len - 1] + last_stmt := node.stmts.last() c.check_or_last_stmt(last_stmt, ret_type, expr_return_type.clear_flag(.optional).clear_flag(.result)) } @@ -1537,7 +1537,7 @@ pub fn (mut c Checker) enum_decl(mut node ast.EnumDecl) { } else { if signed { if iseen.len > 0 { - ilast := iseen[iseen.len - 1] + ilast := iseen.last() if ilast == enum_imax { c.error('enum value overflows type `$senum_type`, which has a maximum value of $enum_imax', field.pos) @@ -1551,7 +1551,7 @@ pub fn (mut c Checker) enum_decl(mut node ast.EnumDecl) { } } else { if useen.len > 0 { - ulast := useen[useen.len - 1] + ulast := useen.last() if ulast == enum_umax { c.error('enum value overflows type `$senum_type`, which has a maximum value of $enum_umax', field.pos) diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 4bea8c92c5..be525218ec 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -925,7 +925,7 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) } param := if func.is_variadic && i >= func.params.len - 1 { - func.params[func.params.len - 1] + func.params.last() } else { func.params[i] } @@ -1182,7 +1182,7 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) if func.generic_names.len > 0 { for i, mut call_arg in node.args { param := if func.is_variadic && i >= func.params.len - 1 { - func.params[func.params.len - 1] + func.params.last() } else { func.params[i] } diff --git a/vlib/v/checker/match.v b/vlib/v/checker/match.v index 9ab1f21353..75834a821d 100644 --- a/vlib/v/checker/match.v +++ b/vlib/v/checker/match.v @@ -338,7 +338,7 @@ fn (mut c Checker) match_exprs(mut node ast.MatchExpr, cond_type_sym ast.TypeSym } } } - mut else_branch := node.branches[node.branches.len - 1] + mut else_branch := node.branches.last() mut has_else := else_branch.is_else if !has_else { for i, branch in node.branches { diff --git a/vlib/v/depgraph/depgraph.v b/vlib/v/depgraph/depgraph.v index d543b91794..0ffa9475a6 100644 --- a/vlib/v/depgraph/depgraph.v +++ b/vlib/v/depgraph/depgraph.v @@ -148,7 +148,7 @@ pub fn (graph &DepGraph) resolve() &DepGraph { } pub fn (graph &DepGraph) last_node() DepGraphNode { - return graph.nodes[graph.nodes.len - 1] + return graph.nodes.last() } pub fn (graph &DepGraph) display() string { diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 0f348ea53c..4b21b7bb9b 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -132,7 +132,7 @@ pub fn (mut f Fmt) wrap_long_line(penalty_idx int, add_indent bool) bool { if penalty_idx > 0 && f.line_len <= fmt.max_len[penalty_idx] { return false } - if f.out[f.out.len - 1] == ` ` { + if f.out.last() == ` ` { f.out.go_back(1) } f.write('\n') @@ -255,7 +255,7 @@ pub fn (mut f Fmt) short_module(name string) string { } idx := vals.len - 1 mname, tprefix := f.get_modname_prefix(vals[..idx].join('.')) - symname := vals[vals.len - 1] + symname := vals.last() mut aname := f.mod2alias[mname] if aname == '' { for _, v in f.mod2alias { @@ -1955,7 +1955,7 @@ pub fn (mut f Fmt) ident(node ast.Ident) { // "v.fmt.foo" => "fmt.foo" vals := full_name.split('.') mod_prefix := vals[vals.len - 2] - const_name := vals[vals.len - 1] + const_name := vals.last() if mod_prefix == 'main' { f.write(const_name) return diff --git a/vlib/v/fmt/struct.v b/vlib/v/fmt/struct.v index 14fd48ea28..7b63c8af4e 100644 --- a/vlib/v/fmt/struct.v +++ b/vlib/v/fmt/struct.v @@ -264,7 +264,7 @@ pub fn (mut f Fmt) struct_init(node ast.StructInit) { fields_start := f.out.len fields_loop: for { if !single_line_fields { - if use_short_args && f.out[f.out.len - 1] == ` ` { + if use_short_args && f.out.last() == ` ` { // v Remove space at tail of line // f(a, b, c, \n // f1: 0\n diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 762b3623b9..bdc3291a83 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -2529,7 +2529,7 @@ fn (mut g Gen) asm_stmt(stmt ast.AsmStmt) { } // swap destionation and operands for att syntax if template.args.len != 0 && !template.is_directive { - template.args.prepend(template.args[template.args.len - 1]) + template.args.prepend(template.args.last()) template.args.delete(template.args.len - 1) } diff --git a/vlib/v/gen/c/comptime.v b/vlib/v/gen/c/comptime.v index 5a8c023c48..0910b849d6 100644 --- a/vlib/v/gen/c/comptime.v +++ b/vlib/v/gen/c/comptime.v @@ -98,7 +98,7 @@ fn (mut g Gen) comptime_call(mut node ast.ComptimeCall) { g.error('method `${m.name}()` (no value) used as value', node.pos) } expand_strs := if node.args.len > 0 && m.params.len - 1 >= node.args.len { - arg := node.args[node.args.len - 1] + arg := node.args.last() param := m.params[node.args.len] arg.expr is ast.Ident && g.table.type_to_str(arg.typ) == '[]string' diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index a60aa55184..689ad5f7b5 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -848,7 +848,7 @@ fn (mut g Gen) method_call(node ast.CallExpr) { } g.write('${dot}_object') is_variadic := node.expected_arg_types.len > 0 - && node.expected_arg_types[node.expected_arg_types.len - 1].has_flag(.variadic) + && node.expected_arg_types.last().has_flag(.variadic) if node.args.len > 0 || is_variadic { g.write(', ') g.call_args(node) @@ -1202,7 +1202,7 @@ fn (mut g Gen) method_call(node ast.CallExpr) { g.write(')') } is_variadic := node.expected_arg_types.len > 0 - && node.expected_arg_types[node.expected_arg_types.len - 1].has_flag(.variadic) + && node.expected_arg_types.last().has_flag(.variadic) if node.args.len > 0 || is_variadic { g.write(', ') } @@ -1784,8 +1784,8 @@ fn (mut g Gen) call_args(node ast.CallExpr) { // Handle `foo(c'str')` for `fn foo(args ...&u8)` // TODOC2V handle this in a better place g.expr(args[0].expr) - } else if args.len > 0 && args[args.len - 1].expr is ast.ArrayDecompose { - g.expr(args[args.len - 1].expr) + } else if args.len > 0 && args.last().expr is ast.ArrayDecompose { + g.expr(args.last().expr) } else { if variadic_count > 0 { if g.pref.translated || g.file.is_translated { diff --git a/vlib/v/gen/golang/golang.v b/vlib/v/gen/golang/golang.v index c215adca64..a098cde1c2 100644 --- a/vlib/v/gen/golang/golang.v +++ b/vlib/v/gen/golang/golang.v @@ -113,7 +113,7 @@ pub fn (mut f Gen) wrap_long_line(penalty_idx int, add_indent bool) bool { if f.buffering { return false } - if f.out[f.out.len - 1] == ` ` { + if f.out.last() == ` ` { f.out.go_back(1) } f.write('\n') @@ -220,7 +220,7 @@ pub fn (mut f Gen) short_module(name string) string { } idx := vals.len - 1 mname, tprefix := f.get_modname_prefix(vals[..idx].join('.')) - symname := vals[vals.len - 1] + symname := vals.last() mut aname := f.mod2alias[mname] if aname == '' { for _, v in f.mod2alias { diff --git a/vlib/v/gen/golang/struct.v b/vlib/v/gen/golang/struct.v index d5908ce88e..24427e01dd 100644 --- a/vlib/v/gen/golang/struct.v +++ b/vlib/v/gen/golang/struct.v @@ -166,7 +166,7 @@ pub fn (mut f Gen) struct_init(node ast.StructInit) { // fields_start := f.out.len fields_loop: for { if !single_line_fields { - if use_short_args && f.out[f.out.len - 1] == ` ` { + if use_short_args && f.out.last() == ` ` { // v Remove space at tail of line // f(a, b, c, \n // f1: 0\n diff --git a/vlib/v/gen/js/js.v b/vlib/v/gen/js/js.v index 346aa5f3f7..13e0a097c9 100644 --- a/vlib/v/gen/js/js.v +++ b/vlib/v/gen/js/js.v @@ -284,7 +284,7 @@ pub fn gen(files []&ast.File, table &ast.Table, pref &pref.Preferences) string { /* if pref.is_shared { // Export, through CommonJS, the module of the entry file if `-shared` was passed - export := nodes[nodes.len - 1].name + export := nodes.last().name out += 'if (typeof module === "object" && module.exports) module.exports = $export;\n' }*/ out += '\n' @@ -3584,7 +3584,7 @@ fn (mut g JsGen) gen_type_cast_expr(it ast.CastExpr) { return } if g.cast_stack.len > 0 && is_literal { - if it.typ == g.cast_stack[g.cast_stack.len - 1] { + if it.typ == g.cast_stack.last() { g.expr(it.expr) return } @@ -3619,7 +3619,7 @@ fn (mut g JsGen) gen_integer_literal_expr(it ast.IntegerLiteral) { // Don't wrap integers for use in JS.foo functions. // TODO: call.language always seems to be "v", parser bug? if g.call_stack.len > 0 { - call := g.call_stack[g.call_stack.len - 1] + call := g.call_stack.last() if call.language == .js { for t in call.args { if t.expr is ast.IntegerLiteral { @@ -3634,7 +3634,7 @@ fn (mut g JsGen) gen_integer_literal_expr(it ast.IntegerLiteral) { // Skip cast if type is the same as the parrent caster if g.cast_stack.len > 0 { - if g.cast_stack[g.cast_stack.len - 1] in ast.integer_type_idxs { + if g.cast_stack.last() in ast.integer_type_idxs { g.write('new ') g.write('int($it.val)') @@ -3652,7 +3652,7 @@ fn (mut g JsGen) gen_float_literal_expr(it ast.FloatLiteral) { // Don't wrap integers for use in JS.foo functions. // TODO: call.language always seems to be "v", parser bug? if g.call_stack.len > 0 { - call := g.call_stack[g.call_stack.len - 1] + call := g.call_stack.last() if call.language == .js { for i, t in call.args { if t.expr is ast.FloatLiteral { @@ -3671,10 +3671,10 @@ fn (mut g JsGen) gen_float_literal_expr(it ast.FloatLiteral) { // Skip cast if type is the same as the parrent caster if g.cast_stack.len > 0 { - if g.cast_stack[g.cast_stack.len - 1] in ast.float_type_idxs { + if g.cast_stack.last() in ast.float_type_idxs { g.write('new f32($it.val)') return - } else if g.cast_stack[g.cast_stack.len - 1] in ast.integer_type_idxs { + } else if g.cast_stack.last() in ast.integer_type_idxs { g.write(int(it.val.f64()).str()) return } diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v index 31f19b8fc0..c62566f642 100644 --- a/vlib/v/parser/parse_type.v +++ b/vlib/v/parser/parse_type.v @@ -310,7 +310,7 @@ pub fn (mut p Parser) parse_inline_sum_type() ast.Type { variants := p.parse_sum_type_variants() if variants.len > 1 { if variants.len > parser.maximum_inline_sum_type_variants { - pos := variants[0].pos.extend(variants[variants.len - 1].pos) + pos := variants[0].pos.extend(variants.last().pos) p.warn_with_pos('an inline sum type expects a maximum of $parser.maximum_inline_sum_type_variants types ($variants.len were given)', pos) } diff --git a/vlib/v/util/suggestions.v b/vlib/v/util/suggestions.v index 568c4d4739..c7ad838b00 100644 --- a/vlib/v/util/suggestions.v +++ b/vlib/v/util/suggestions.v @@ -106,7 +106,7 @@ pub fn short_module_name(name string) string { return name } mname := vals[vals.len - 2] - symname := vals[vals.len - 1] + symname := vals.last() return '${mname}.$symname' }