checker: arr1=arr2 warning
parent
4a5fb854e0
commit
875f7a77a9
|
@ -361,7 +361,10 @@ fn test_clone() {
|
|||
|
||||
fn test_copy() {
|
||||
a := [1, 2, 3]
|
||||
b := [3, 4, 5]
|
||||
b := a
|
||||
assert b[0] == 1
|
||||
assert b[1] == 2
|
||||
assert b[2] == 3
|
||||
}
|
||||
|
||||
fn test_mutli_array_clone() {
|
||||
|
|
|
@ -11,7 +11,7 @@ pub fn args_after(cut_word string) []string {
|
|||
}
|
||||
mut cargs := []string{}
|
||||
if cut_word !in args {
|
||||
cargs = args
|
||||
cargs = args.clone()
|
||||
} else {
|
||||
mut found := false
|
||||
cargs << args[0]
|
||||
|
@ -37,7 +37,7 @@ pub fn args_before(cut_word string) []string {
|
|||
}
|
||||
mut cargs := []string{}
|
||||
if cut_word !in args {
|
||||
cargs = args
|
||||
cargs = args.clone()
|
||||
} else {
|
||||
cargs << args[0]
|
||||
for a in args[1..] {
|
||||
|
|
|
@ -2209,6 +2209,11 @@ pub fn (mut c Checker) assign_stmt(mut assign_stmt ast.AssignStmt) {
|
|||
// TODO replace all c.pref.translated checks with `$if !translated` for performance
|
||||
continue
|
||||
}
|
||||
if left_sym.kind == .array &&
|
||||
assign_stmt.op == .assign && right_sym.kind == .array && left is ast.Ident && right is ast.Ident {
|
||||
// Do not allow `a = b`, only `a = b.clone()`
|
||||
c.warn('use `array2 = array1.clone()` instead of `array1 = array2`', assign_stmt.pos)
|
||||
}
|
||||
left_is_ptr := left_type.is_ptr() || left_sym.is_pointer()
|
||||
if left_is_ptr {
|
||||
if !c.inside_unsafe && assign_stmt.op !in [.assign, .decl_assign] {
|
||||
|
@ -2321,6 +2326,7 @@ pub fn (mut c Checker) assign_stmt(mut assign_stmt ast.AssignStmt) {
|
|||
}
|
||||
}
|
||||
}
|
||||
// right_sym := c.table.get_type_symbol(right_type_unwrapped)
|
||||
}
|
||||
|
||||
fn scope_register_it(mut s ast.Scope, pos token.Position, typ table.Type) {
|
||||
|
|
|
@ -97,7 +97,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
|
|||
}
|
||||
}
|
||||
if p.tok.kind == .rcbr {
|
||||
end_comments = comments
|
||||
end_comments = comments.clone()
|
||||
break
|
||||
}
|
||||
if p.tok.kind == .key_pub {
|
||||
|
|
|
@ -154,7 +154,7 @@ fn (mut mcache ModFileCacher) get_files(cfolder string) []string {
|
|||
mut files := []string{}
|
||||
if os.exists(cfolder) && os.is_dir(cfolder) {
|
||||
if listing := os.ls(cfolder) {
|
||||
files = listing
|
||||
files = listing.clone()
|
||||
}
|
||||
}
|
||||
mcache.folder_files[cfolder] = files
|
||||
|
|
Loading…
Reference in New Issue