mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix dereferencing voidptr. (#15033)
This commit is contained in:
parent
dc68469818
commit
f35a3a89f9
@ -331,6 +331,11 @@ pub fn (typ Type) is_pointer() bool {
|
||||
return typ.idx() in ast.pointer_type_idxs
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn (typ Type) is_voidptr() bool {
|
||||
return typ.idx() == ast.voidptr_type_idx
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn (typ Type) is_real_pointer() bool {
|
||||
return typ.is_ptr() || typ.is_pointer()
|
||||
|
@ -3305,6 +3305,9 @@ pub fn (mut c Checker) prefix_expr(mut node ast.PrefixExpr) ast.Type {
|
||||
s := c.table.type_to_str(right_type)
|
||||
c.error('invalid indirect of `$s`', node.pos)
|
||||
}
|
||||
if right_type.is_voidptr() {
|
||||
c.error('cannot dereference to void', node.pos)
|
||||
}
|
||||
}
|
||||
if node.op == .bit_not && !right_type.is_int() && !c.pref.translated && !c.file.is_translated {
|
||||
c.error('operator ~ only defined on int types', node.pos)
|
||||
|
6
vlib/v/checker/tests/voidptr_dereference_err.out
Normal file
6
vlib/v/checker/tests/voidptr_dereference_err.out
Normal file
@ -0,0 +1,6 @@
|
||||
vlib/v/checker/tests/voidptr_dereference_err.vv:5:10: error: cannot dereference to void
|
||||
3 | mut b := 123
|
||||
4 | a = &b
|
||||
5 | println(*a)
|
||||
| ^
|
||||
6 | }
|
6
vlib/v/checker/tests/voidptr_dereference_err.vv
Normal file
6
vlib/v/checker/tests/voidptr_dereference_err.vv
Normal file
@ -0,0 +1,6 @@
|
||||
fn main() {
|
||||
mut a := voidptr(0)
|
||||
mut b := 123
|
||||
a = &b
|
||||
println(*a)
|
||||
}
|
Loading…
Reference in New Issue
Block a user