mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
compiler: fix a deferencing cast was causing a segfault
This commit is contained in:
parent
8fbfceed30
commit
4edade5067
@ -538,7 +538,7 @@ fn (p mut Parser) cast(typ string) {
|
|||||||
p.error('cannot cast `$expr_typ` to `$typ`, use backquotes `` to create a `$typ` or access the value of an index of `$expr_typ` using []')
|
p.error('cannot cast `$expr_typ` to `$typ`, use backquotes `` to create a `$typ` or access the value of an index of `$expr_typ` using []')
|
||||||
}
|
}
|
||||||
else if casting_voidptr_to_value {
|
else if casting_voidptr_to_value {
|
||||||
p.cgen.set_placeholder(pos, '*($typ*)(')
|
p.cgen.set_placeholder(pos, '($typ)(')
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Nothing can be cast to bool
|
// Nothing can be cast to bool
|
||||||
|
11
vlib/compiler/tests/voidptr_to_u64_cast_a_test.v
Normal file
11
vlib/compiler/tests/voidptr_to_u64_cast_a_test.v
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fn receive_addr_return_u64 (addr voidptr) u64 {
|
||||||
|
return u64(addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_void_pointer_to_u64_cast_via_fn_call() {
|
||||||
|
a := u64(10)
|
||||||
|
b := voidptr(a)
|
||||||
|
c := receive_addr_return_u64(b)
|
||||||
|
assert (a == c)
|
||||||
|
}
|
||||||
|
|
11
vlib/compiler/tests/voidptr_to_u64_cast_b_test.v
Normal file
11
vlib/compiler/tests/voidptr_to_u64_cast_b_test.v
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fn receive_u64_return_addr (something u64) voidptr {
|
||||||
|
return voidptr(something)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_u64_to_void_pointer_cast_via_fn_call() {
|
||||||
|
a := u64(100)
|
||||||
|
b := receive_u64_return_addr(a)
|
||||||
|
c := u64(b)
|
||||||
|
assert (a == c)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user