mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: disallow &nil (#17283)
This commit is contained in:
parent
04e00a46d4
commit
fbcb1f3711
@ -3643,6 +3643,9 @@ fn (mut c Checker) prefix_expr(mut node ast.PrefixExpr) ast.Type {
|
|||||||
c.inside_ref_lit = old_inside_ref_lit
|
c.inside_ref_lit = old_inside_ref_lit
|
||||||
node.right_type = right_type
|
node.right_type = right_type
|
||||||
if node.op == .amp {
|
if node.op == .amp {
|
||||||
|
if node.right is ast.Nil {
|
||||||
|
c.error('invalid operation: cannot take address of nil', node.right.pos())
|
||||||
|
}
|
||||||
if mut node.right is ast.PrefixExpr {
|
if mut node.right is ast.PrefixExpr {
|
||||||
if node.right.op == .amp {
|
if node.right.op == .amp {
|
||||||
c.error('unexpected `&`, expecting expression', node.right.pos)
|
c.error('unexpected `&`, expecting expression', node.right.pos)
|
||||||
|
6
vlib/v/checker/tests/invalid_nilref_err.out
Normal file
6
vlib/v/checker/tests/invalid_nilref_err.out
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
vlib/v/checker/tests/invalid_nilref_err.vv:2:19: error: invalid operation: cannot take address of nil
|
||||||
|
1 | fn main() {
|
||||||
|
2 | var := unsafe { &nil }
|
||||||
|
| ~~~
|
||||||
|
3 | println(var)
|
||||||
|
4 | }
|
4
vlib/v/checker/tests/invalid_nilref_err.vv
Normal file
4
vlib/v/checker/tests/invalid_nilref_err.vv
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
fn main() {
|
||||||
|
var := unsafe { &nil }
|
||||||
|
println(var)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user