checker: add error when trying to take address of call expr
parent
4770036e23
commit
317d450723
|
@ -5127,21 +5127,25 @@ pub fn (mut c Checker) prefix_expr(mut node ast.PrefixExpr) table.Type {
|
||||||
node.right_type = right_type
|
node.right_type = right_type
|
||||||
// TODO: testing ref/deref strategy
|
// TODO: testing ref/deref strategy
|
||||||
if node.op == .amp && !right_type.is_ptr() {
|
if node.op == .amp && !right_type.is_ptr() {
|
||||||
match node.right {
|
right_expr := node.right
|
||||||
ast.IntegerLiteral {
|
match right_expr {
|
||||||
c.error('cannot take the address of an int literal', node.pos)
|
|
||||||
}
|
|
||||||
ast.BoolLiteral {
|
ast.BoolLiteral {
|
||||||
c.error('cannot take the address of a bool literal', node.pos)
|
c.error('cannot take the address of a bool literal', node.pos)
|
||||||
}
|
}
|
||||||
ast.StringLiteral, ast.StringInterLiteral {
|
ast.CallExpr {
|
||||||
c.error('cannot take the address of a string literal', node.pos)
|
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 {
|
ast.FloatLiteral {
|
||||||
c.error('cannot take the address of a float literal', node.pos)
|
c.error('cannot take the address of a float literal', node.pos)
|
||||||
}
|
}
|
||||||
ast.CharLiteral {
|
ast.IntegerLiteral {
|
||||||
c.error('cannot take the address of a char literal', node.pos)
|
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 {}
|
else {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue