Skip to content

Commit ba9d358

Browse files
authored
checker: fix missing check for invalid prefixexpr expression &(&var) (fix #23365) (#23418)
1 parent cc7caf4 commit ba9d358

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

vlib/v/checker/checker.v

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4679,6 +4679,12 @@ fn (mut c Checker) prefix_expr(mut node ast.PrefixExpr) ast.Type {
46794679
if node.right.op == .amp {
46804680
c.error('unexpected `&`, expecting expression', node.right.pos)
46814681
}
4682+
} else if mut node.right is ast.ParExpr {
4683+
if mut node.right.expr is ast.PrefixExpr {
4684+
if node.right.expr.op == .amp {
4685+
c.error('cannot take the address of this expression', node.right.pos)
4686+
}
4687+
}
46824688
} else if mut node.right is ast.SelectorExpr {
46834689
if node.right.expr.is_literal() {
46844690
c.error('cannot take the address of a literal value', node.pos.extend(node.right.pos))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
vlib/v/checker/tests/addr_of_invalid_expr.vv:3:8: error: cannot take the address of this expression
2+
1 | fn main() {
3+
2 | a := 1
4+
3 | _ := &(&a)
5+
| ~~~~
6+
4 | }
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
a := 1
3+
_ := &(&a)
4+
}

0 commit comments

Comments
 (0)