@@ -4671,6 +4671,11 @@ fn (mut c Checker) prefix_expr(mut node ast.PrefixExpr) ast.Type {
46714671 right_type := c.expr (mut node.right)
46724672 c.inside_ref_lit = old_inside_ref_lit
46734673 node.right_type = right_type
4674+ mut expr := node.right
4675+ // if ParExpr get the innermost expr
4676+ for mut expr is ast.ParExpr {
4677+ expr = expr.expr
4678+ }
46744679 if node.op == .amp {
46754680 if node.right is ast.Nil {
46764681 c.error ('invalid operation: cannot take address of nil' , node.right.pos ())
@@ -4679,11 +4684,9 @@ fn (mut c Checker) prefix_expr(mut node ast.PrefixExpr) ast.Type {
46794684 if node.right.op == .amp {
46804685 c.error ('unexpected `&`, expecting expression' , node.right.pos)
46814686 }
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+ } else if mut expr is ast.PrefixExpr {
4688+ if expr.op == .amp {
4689+ c.error ('cannot take the address of this expression' , expr.pos)
46874690 }
46884691 } else if mut node.right is ast.SelectorExpr {
46894692 if node.right.expr.is_literal () {
@@ -4710,11 +4713,6 @@ fn (mut c Checker) prefix_expr(mut node ast.PrefixExpr) ast.Type {
47104713 // TODO: testing ref/deref strategy
47114714 right_is_ptr := right_type.is_ptr ()
47124715 if node.op == .amp && (! right_is_ptr || (right_is_ptr && node.right is ast.CallExpr )) {
4713- mut expr := node.right
4714- // if ParExpr get the innermost expr
4715- for mut expr is ast.ParExpr {
4716- expr = expr.expr
4717- }
47184716 if expr in [ast.BoolLiteral, ast.CallExpr, ast.CharLiteral, ast.FloatLiteral, ast.IntegerLiteral,
47194717 ast.InfixExpr, ast.StringLiteral, ast.StringInterLiteral] {
47204718 c.error ('cannot take the address of ${expr }' , node.pos)
0 commit comments