mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: do not allow arr1=arr2 without cloning
This commit is contained in:
parent
583c02316a
commit
6bf21c300a
@ -296,7 +296,7 @@ pub fn prepare_test_session(zargs string, folder string, oskipped []string, main
|
||||
mut session := new_test_session(vargs)
|
||||
files := os.walk_ext(os.join_path(parent_dir, folder), '.v')
|
||||
mut mains := []string{}
|
||||
mut skipped := oskipped
|
||||
mut skipped := oskipped.clone()
|
||||
for f in files {
|
||||
if !f.contains('modules') && !f.contains('preludes') {
|
||||
// $if !linux {
|
||||
|
@ -42,7 +42,7 @@ fn main() {
|
||||
vexe := pref.vexe_path()
|
||||
vroot := os.dir(vexe)
|
||||
os.chdir(vroot)
|
||||
args := os.args
|
||||
args := os.args.clone()
|
||||
args_string := args[1..].join(' ')
|
||||
cmd_prefix := args_string.all_before('test-fixed')
|
||||
title := 'testing all fixed tests'
|
||||
|
@ -359,6 +359,7 @@ fn test_clone() {
|
||||
assert nums.slice(1, 3).str() == '[2, 3]'
|
||||
}
|
||||
|
||||
/*
|
||||
fn test_copy() {
|
||||
a := [1, 2, 3]
|
||||
b := a
|
||||
@ -366,7 +367,7 @@ fn test_copy() {
|
||||
assert b[1] == 2
|
||||
assert b[2] == 3
|
||||
}
|
||||
|
||||
*/
|
||||
fn test_mutli_array_clone() {
|
||||
// 2d array_int
|
||||
mut a2_1 := [[1, 2, 3], [4, 5, 6]]
|
||||
@ -683,7 +684,7 @@ fn test_array_str() {
|
||||
numbers := [1, 2, 3]
|
||||
assert numbers == [1, 2, 3]
|
||||
numbers2 := [numbers, [4, 5, 6]] // dup str() bug
|
||||
_ = numbers2
|
||||
println(numbers2)
|
||||
assert true
|
||||
assert numbers.str() == '[1, 2, 3]'
|
||||
// QTODO
|
||||
|
@ -2213,7 +2213,7 @@ pub fn (mut c Checker) assign_stmt(mut assign_stmt ast.AssignStmt) {
|
||||
assign_stmt.op in [.assign, .decl_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 `array2 = array1`', assign_stmt.pos)
|
||||
c.error('use `array2 = array1.clone()` instead of `array2 = array1`', assign_stmt.pos)
|
||||
}
|
||||
left_is_ptr := left_type.is_ptr() || left_sym.is_pointer()
|
||||
if left_is_ptr {
|
||||
|
@ -4,7 +4,7 @@ import os
|
||||
fn simple() {
|
||||
nums := [1, 2, 3] // local array must be freed
|
||||
println(nums)
|
||||
nums_copy := nums // array assignments call .clone()
|
||||
nums_copy := nums.clone() // array assignments call .clone()
|
||||
println(nums_copy)
|
||||
name := 'Peter' // string literals mustn't be freed
|
||||
str_inter := 'hello, $name' // concatenated strings must be freed
|
||||
|
Loading…
Reference in New Issue
Block a user