Skip to content

Commit

Permalink
checker: check fn call argument mismatch for array struct type (#18975)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Jul 26, 2023
1 parent 94de6f6 commit 7d6fd9d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion vlib/v/checker/check_types.v
Expand Up @@ -350,7 +350,8 @@ fn (mut c Checker) check_basic(got ast.Type, expected ast.Type) bool {
return true
}
// TODO: use sym so it can be absorbed into below [.voidptr, .any] logic
if expected.idx() == ast.array_type_idx || got.idx() == ast.array_type_idx {
if (expected.idx() == ast.array_type_idx && c.table.final_sym(got).kind == .array)
|| (got.idx() == ast.array_type_idx && c.table.final_sym(expected).kind == .array) {
return true
}
got_sym, exp_sym := c.table.sym(got), c.table.sym(expected)
Expand Down
7 changes: 7 additions & 0 deletions vlib/v/checker/tests/fn_call_arg_array_mismatch_err.out
@@ -0,0 +1,7 @@
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 {
| ~~~~~~~~~~~~
10 | eprintln('Error: write file service')
11 | exit(1)
13 changes: 13 additions & 0 deletions vlib/v/checker/tests/fn_call_arg_array_mismatch_err.vv
@@ -0,0 +1,13 @@
import os

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

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

0 comments on commit 7d6fd9d

Please sign in to comment.