Disallow unary plus at the parsing stage

This commit is contained in:
Kamil Śliwak
2023-04-18 16:47:00 +02:00
parent ee1b50d345
commit 8a14680851
9 changed files with 27 additions and 20 deletions
+1 -3
View File
@@ -332,9 +332,7 @@ bool SyntaxChecker::visit(Literal const& _literal)
bool SyntaxChecker::visit(UnaryOperation const& _operation)
{
if (_operation.getOperator() == Token::Add)
m_errorReporter.syntaxError(9636_error, _operation.location(), "Use of unary + is disallowed.");
solAssert(_operation.getOperator() != Token::Add);
return true;
}
+3 -2
View File
@@ -819,16 +819,17 @@ BoolResult FixedPointType::isExplicitlyConvertibleTo(Type const& _convertTo) con
TypeResult FixedPointType::unaryOperatorResult(Token _operator) const
{
solAssert(_operator != Token::Add);
switch (_operator)
{
case Token::Delete:
// "delete" is ok for all fixed types
return TypeResult{TypeProvider::emptyTuple()};
case Token::Add:
case Token::Sub:
case Token::Inc:
case Token::Dec:
// for fixed, we allow +, -, ++ and --
// for fixed, we allow -, ++ and --
return this;
default:
return nullptr;
+2 -2
View File
@@ -511,8 +511,8 @@ bool ExpressionCompiler::visit(UnaryOperation const& _unaryOperation)
m_currentLValue.reset();
break;
case Token::Add: // +
// unary add, so basically no-op
break;
// According to SyntaxChecker...
solAssert(false, "Use of unary + is disallowed.");
case Token::Sub: // -
solUnimplementedAssert(
type.category() != Type::Category::FixedPoint,
+4
View File
@@ -1863,6 +1863,10 @@ ASTPointer<Expression> Parser::parseUnaryExpression(
ASTNodeFactory nodeFactory = _partiallyParsedExpression ?
ASTNodeFactory(*this, _partiallyParsedExpression) : ASTNodeFactory(*this);
Token token = m_scanner->currentToken();
if (token == Token::Add)
fatalParserError(9636_error, "Use of unary + is disallowed.");
if (!_partiallyParsedExpression && (TokenTraits::isUnaryOp(token) || TokenTraits::isCountOp(token)))
{
// prefix expression