Skip to content

Commit b83ce21

Browse files
authored
checker: cleanup in assign_stmt() (#20880)
1 parent 13fbf35 commit b83ce21

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

vlib/v/checker/assign.v

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,11 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
365365
}
366366
} else if mut right is ast.Ident && right.obj is ast.Var
367367
&& right.or_expr.kind == .absent {
368-
if (right.obj as ast.Var).ct_type_var != .no_comptime {
368+
right_obj_var := right.obj as ast.Var
369+
if right_obj_var.ct_type_var != .no_comptime {
369370
ctyp := c.comptime.get_comptime_var_type(right)
370371
if ctyp != ast.void_type {
371-
left.obj.ct_type_var = (right.obj as ast.Var).ct_type_var
372+
left.obj.ct_type_var = right_obj_var.ct_type_var
372373
left.obj.typ = ctyp
373374
}
374375
}
@@ -522,10 +523,9 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
522523
}
523524
} else if mut left is ast.Ident && left.kind != .blank_ident
524525
&& right is ast.IndexExpr {
525-
if (right as ast.IndexExpr).left is ast.Ident
526-
&& (right as ast.IndexExpr).index is ast.RangeExpr
527-
&& ((right as ast.IndexExpr).left.is_mut() || left.is_mut())
528-
&& !c.inside_unsafe {
526+
right_index_expr := right as ast.IndexExpr
527+
if right_index_expr.left is ast.Ident && right_index_expr.index is ast.RangeExpr
528+
&& (right_index_expr.left.is_mut() || left.is_mut()) && !c.inside_unsafe {
529529
// `mut a := arr[..]` auto add clone() -> `mut a := arr[..].clone()`
530530
c.add_error_detail_with_pos('To silence this notice, use either an explicit `a[..].clone()`,
531531
or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',

0 commit comments

Comments
 (0)