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

checker: fix generic_mutable_arrays in functions (#8445)

This commit is contained in:
BigBlack 2021-01-31 01:35:03 +08:00 committed by GitHub
parent 64d12cdc8d
commit c5e7956eb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -1359,3 +1359,12 @@ fn test_clone_of_same_elem_size_array() {
println(arr2) println(arr2)
assert arr2 == [Abc{1, 2, 3}, Abc{2, 3, 4}] assert arr2 == [Abc{1, 2, 3}, Abc{2, 3, 4}]
} }
pub fn example<T>(mut arr []T) []T {
return arr.clone()
}
fn test_generic_mutable_arrays() {
mut arr := [1, 2, 3]
assert example(mut arr) == [1, 2, 3]
}

View File

@ -1356,7 +1356,7 @@ pub fn (mut c Checker) call_method(mut call_expr ast.CallExpr) table.Type {
// need to return `array_xxx` instead of `array` // need to return `array_xxx` instead of `array`
// in ['clone', 'str'] { // in ['clone', 'str'] {
call_expr.receiver_type = left_type.to_ptr() call_expr.receiver_type = left_type.to_ptr()
// call_expr.return_type = call_expr.receiver_type call_expr.return_type = call_expr.receiver_type.set_nr_muls(0)
} else if method_name == 'sort' { } else if method_name == 'sort' {
call_expr.return_type = table.void_type call_expr.return_type = table.void_type
} else if method_name == 'contains' { } else if method_name == 'contains' {