1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: update check for arr=arr1 (#7651)

This commit is contained in:
Swastik Baranwal 2020-12-28 23:05:34 +05:30 committed by GitHub
parent 9631eac9c5
commit 2795f929fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -352,6 +352,7 @@ fn test_mut_arg() {
fn test_clone() {
nums := [1, 2, 3, 4, 100]
_ = nums
nums2 := nums.clone()
assert nums2.len == 5
assert nums.str() == '[1, 2, 3, 4, 100]'

View File

@ -2293,7 +2293,8 @@ pub fn (mut c Checker) assign_stmt(mut assign_stmt ast.AssignStmt) {
continue
}
if left_sym.kind == .array && !c.inside_unsafe && assign_stmt.op in [.assign, .decl_assign] &&
right_sym.kind == .array && left is ast.Ident && right is ast.Ident {
right_sym.kind == .array &&
(left is ast.Ident && !left.is_blank_ident()) && right is ast.Ident {
// Do not allow `a = b`, only `a = b.clone()`
c.error('use `array2 = array1.clone()` instead of `array2 = array1` (or use `unsafe`)',
assign_stmt.pos)