Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Jan 9, 2025
1 parent 6348e58 commit 57f92eb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions vlib/v/checker/checker.v
Original file line number Diff line number Diff line change
Expand Up @@ -4679,6 +4679,12 @@ fn (mut c Checker) prefix_expr(mut node ast.PrefixExpr) ast.Type {
if node.right.op == .amp {
c.error('unexpected `&`, expecting expression', node.right.pos)
}
} else if mut node.right is ast.ParExpr {
if mut node.right.expr is ast.PrefixExpr {
if node.right.expr.op == .amp {
c.error('cannot take the address of this expression', node.right.pos)
}
}
} else if mut node.right is ast.SelectorExpr {
if node.right.expr.is_literal() {
c.error('cannot take the address of a literal value', node.pos.extend(node.right.pos))
Expand Down
6 changes: 6 additions & 0 deletions vlib/v/checker/tests/addr_of_invalid_expr.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
vlib/v/checker/tests/addr_of_invalid_expr.vv:3:8: error: cannot take the address of this expression
1 | fn main() {
2 | a := 1
3 | _ := &(&a)
| ~~~~
4 | }
4 changes: 4 additions & 0 deletions vlib/v/checker/tests/addr_of_invalid_expr.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
a := 1
_ := &(&a)
}

0 comments on commit 57f92eb

Please sign in to comment.