mirror of
https://github.com/vlang/v.git
synced 2025-09-11 08:25:42 -04:00
checker: fix voidptr type checking (#21923)
This commit is contained in:
parent
ac136c08e6
commit
521c8156bc
@ -304,6 +304,17 @@ fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type, lan
|
|||||||
}
|
}
|
||||||
|
|
||||||
if c.check_types(got, expected) {
|
if c.check_types(got, expected) {
|
||||||
|
if language == .v && idx_got == ast.voidptr_type_idx {
|
||||||
|
if expected.is_int_valptr() || expected.is_int() || expected.is_ptr() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
exp_sym := c.table.final_sym(expected)
|
||||||
|
if exp_sym.language == .v
|
||||||
|
&& exp_sym.kind !in [.voidptr, .charptr, .byteptr, .function, .placeholder, .array_fixed, .struct_] {
|
||||||
|
got_typ_str, expected_typ_str := c.get_string_names_of(got, expected)
|
||||||
|
return error('cannot use `${got_typ_str}` as `${expected_typ_str}`')
|
||||||
|
}
|
||||||
|
}
|
||||||
if language != .v || expected.is_ptr() == got.is_ptr() || arg.is_mut
|
if language != .v || expected.is_ptr() == got.is_ptr() || arg.is_mut
|
||||||
|| arg.expr.is_auto_deref_var() || got.has_flag(.shared_f)
|
|| arg.expr.is_auto_deref_var() || got.has_flag(.shared_f)
|
||||||
|| c.table.sym(expected_).kind !in [.array, .map] {
|
|| c.table.sym(expected_).kind !in [.array, .map] {
|
||||||
|
7
vlib/v/checker/tests/voidptr_arg_err.out
Normal file
7
vlib/v/checker/tests/voidptr_arg_err.out
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
vlib/v/checker/tests/voidptr_arg_err.vv:3:15: error: cannot use `voidptr` as `[]i32` in argument 1 to `test`
|
||||||
|
1 | fn test_main() {
|
||||||
|
2 | c := voidptr(10)
|
||||||
|
3 | println(test(c))
|
||||||
|
| ^
|
||||||
|
4 | }
|
||||||
|
5 |
|
8
vlib/v/checker/tests/voidptr_arg_err.vv
Normal file
8
vlib/v/checker/tests/voidptr_arg_err.vv
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fn test_main() {
|
||||||
|
c := voidptr(10)
|
||||||
|
println(test(c))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test(a []i32) i32 {
|
||||||
|
return a[0]
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user