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

checker: check fn call argument mismatch for array struct type (#18975)

This commit is contained in:
yuyi 2023-07-27 03:17:45 +08:00 committed by GitHub
parent 94de6f62b2
commit 7d6fd9dade
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 1 deletions

View File

@ -350,7 +350,8 @@ fn (mut c Checker) check_basic(got ast.Type, expected ast.Type) bool {
return true return true
} }
// TODO: use sym so it can be absorbed into below [.voidptr, .any] logic // 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 return true
} }
got_sym, exp_sym := c.table.sym(got), c.table.sym(expected) got_sym, exp_sym := c.table.sym(got), c.table.sym(expected)

View File

@ -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)

View File

@ -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)
}
}