From 317d4507239e94bb7ee3ff3f025ded4494af2878 Mon Sep 17 00:00:00 2001 From: Joe Conigliaro Date: Fri, 12 Feb 2021 10:39:02 +1100 Subject: [PATCH] checker: add error when trying to take address of call expr --- vlib/v/checker/checker.v | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index f6ed466772..34144bd5af 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -5127,21 +5127,25 @@ pub fn (mut c Checker) prefix_expr(mut node ast.PrefixExpr) table.Type { node.right_type = right_type // TODO: testing ref/deref strategy if node.op == .amp && !right_type.is_ptr() { - match node.right { - ast.IntegerLiteral { - c.error('cannot take the address of an int literal', node.pos) - } + right_expr := node.right + match right_expr { ast.BoolLiteral { c.error('cannot take the address of a bool literal', node.pos) } - ast.StringLiteral, ast.StringInterLiteral { - c.error('cannot take the address of a string literal', node.pos) + ast.CallExpr { + c.error('cannot take the address of $node.right', node.pos) + } + ast.CharLiteral { + c.error('cannot take the address of a char literal', node.pos) } ast.FloatLiteral { c.error('cannot take the address of a float literal', node.pos) } - ast.CharLiteral { - c.error('cannot take the address of a char literal', node.pos) + ast.IntegerLiteral { + c.error('cannot take the address of an int literal', node.pos) + } + ast.StringLiteral, ast.StringInterLiteral { + c.error('cannot take the address of a string literal', node.pos) } else {} }