Skip to content

Commit

Permalink
checker: fix fu/method mut array dimension mismatch check(fix vlang#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
shove70 committed Dec 14, 2023
1 parent 0b12d64 commit bedd4b5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
6 changes: 2 additions & 4 deletions vlib/v/checker/check_types.v
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,8 @@ fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type, lan
if got_typ_sym.symbol_name_except_generic() == expected_typ_sym.symbol_name_except_generic() {
// Check if we are making a comparison between two different types of
// the same type like `Type[int] and &Type[]`
if got.is_ptr() != expected.is_ptr()
|| !c.check_same_module(got, expected)
|| (!got.is_ptr() && !expected.is_ptr()
&& got_typ_sym.name != expected_typ_sym.name) {
if got.is_ptr() != expected.is_ptr() || !c.check_same_module(got, expected)
|| got_typ_sym.name.trim_left('&') != expected_typ_sym.name.trim_left('&') {
got_typ_str, expected_typ_str := c.get_string_names_of(got, expected)
return error('cannot use `${got_typ_str}` as `${expected_typ_str}`')
}
Expand Down
19 changes: 13 additions & 6 deletions vlib/v/checker/tests/fn_call_arg_array_mismatch_err.out
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
vlib/v/checker/tests/fn_call_arg_array_mismatch_err.vv:9:36: error: cannot use `string` as `array` in argument 2 to `os.write_file_array`
7 |
8 | fn main() {
9 | os.write_file_array(service_path, service_file) or {
vlib/v/checker/tests/fn_call_arg_array_mismatch_err.vv:7:36: error: cannot use `string` as `array` in argument 2 to `os.write_file_array`
5 |
6 | fn main() {
7 | os.write_file_array(service_path, service_file) or {
| ~~~~~~~~~~~~
10 | eprintln('Error: write file service')
11 | exit(1)
8 | eprintln('Error: write file service')
9 | exit(1)
vlib/v/checker/tests/fn_call_arg_array_mismatch_err.vv:16:10: error: cannot use `&[]int` as `&[][]int` in argument 1 to `bar`
14 | // dimension checking error when mut array is passed multiple times as args
15 | fn foo(mut arras []int) {
16 | bar(mut arras)
| ~~~~~
17 | }
18 |
20 changes: 16 additions & 4 deletions vlib/v/checker/tests/fn_call_arg_array_mismatch_err.vv
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
import os

const (
service_file = '[Unit]'
service_path = 'dockerman.service'
)
const service_file = '[Unit]'
const service_path = 'dockerman.service'

fn main() {
os.write_file_array(service_path, service_file) or {
eprintln('Error: write file service')
exit(1)
}
}

// for issue 20172
// dimension checking error when mut array is passed multiple times as args
fn foo(mut arras []int) {
bar(mut arras)
}

fn bar(mut arr [][]int) {
}

fn baz() {
mut arr := [1, 2, 3]
foo(mut arr)
}

0 comments on commit bedd4b5

Please sign in to comment.