mirror of
https://github.com/vlang/v.git
synced 2025-08-03 17:57:59 -04:00
parent
735046a3d4
commit
a65d5ae10f
@ -801,6 +801,14 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',
|
|||||||
if !is_blank_ident && right_sym.kind != .placeholder && left_sym.kind != .interface
|
if !is_blank_ident && right_sym.kind != .placeholder && left_sym.kind != .interface
|
||||||
&& ((!right_type.has_flag(.generic) && !left_type.has_flag(.generic))
|
&& ((!right_type.has_flag(.generic) && !left_type.has_flag(.generic))
|
||||||
|| right_sym.kind != left_sym.kind) {
|
|| right_sym.kind != left_sym.kind) {
|
||||||
|
// Disallow `array = voidptr` assign
|
||||||
|
if left_sym.kind in [.array, .array_fixed]
|
||||||
|
&& (right_type_unwrapped.is_voidptr() || right.is_nil()) {
|
||||||
|
left_str := c.table.type_to_str(left_type_unwrapped)
|
||||||
|
right_str := c.table.type_to_str(right_type_unwrapped)
|
||||||
|
c.error('cannot assign to `${left}`: expected `${left_str}`, not `${right_str}`',
|
||||||
|
right.pos())
|
||||||
|
}
|
||||||
// Dual sides check (compatibility check)
|
// Dual sides check (compatibility check)
|
||||||
c.check_expected(right_type_unwrapped, left_type_unwrapped) or {
|
c.check_expected(right_type_unwrapped, left_type_unwrapped) or {
|
||||||
// allow literal values to auto deref var (e.g.`for mut v in values { v = 1.0 }`)
|
// allow literal values to auto deref var (e.g.`for mut v in values { v = 1.0 }`)
|
||||||
|
19
vlib/v/checker/tests/array_voidptr_assign_err.out
Normal file
19
vlib/v/checker/tests/array_voidptr_assign_err.out
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
vlib/v/checker/tests/array_voidptr_assign_err.vv:2:6: warning: unused variable: `a`
|
||||||
|
1 | fn main() {
|
||||||
|
2 | mut a := []int{}
|
||||||
|
| ^
|
||||||
|
3 | a = unsafe { nil }
|
||||||
|
4 |
|
||||||
|
vlib/v/checker/tests/array_voidptr_assign_err.vv:3:6: error: cannot assign to `a`: expected `[]int`, not `voidptr`
|
||||||
|
1 | fn main() {
|
||||||
|
2 | mut a := []int{}
|
||||||
|
3 | a = unsafe { nil }
|
||||||
|
| ~~~~~~
|
||||||
|
4 |
|
||||||
|
5 | // vfmt off
|
||||||
|
vlib/v/checker/tests/array_voidptr_assign_err.vv:6:6: error: cannot assign to `a`: expected `[]int`, not `voidptr`
|
||||||
|
4 |
|
||||||
|
5 | // vfmt off
|
||||||
|
6 | a = voidptr(0)
|
||||||
|
| ~~~~~~~~~~
|
||||||
|
7 | }
|
7
vlib/v/checker/tests/array_voidptr_assign_err.vv
Normal file
7
vlib/v/checker/tests/array_voidptr_assign_err.vv
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fn main() {
|
||||||
|
mut a := []int{}
|
||||||
|
a = unsafe { nil }
|
||||||
|
|
||||||
|
// vfmt off
|
||||||
|
a = voidptr(0)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user