Merge pull request #14139 from ethereum/make-plus-binary-only

Make plus binary only (second attempt)
This commit is contained in:
Daniel
2023-04-18 21:20:31 +02:00
committed by GitHub
11 changed files with 29 additions and 24 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;
}
+1 -3
View File
@@ -4035,9 +4035,7 @@ void TypeChecker::endVisit(UsingForDirective const& _usingFor)
bool identicalFirstTwoParameters = (parameterCount < 2 || *parameterTypes.at(0) == *parameterTypes.at(1));
bool isUnaryOnlyOperator = (!TokenTraits::isBinaryOp(operator_.value()) && TokenTraits::isUnaryOp(operator_.value()));
bool isBinaryOnlyOperator =
(TokenTraits::isBinaryOp(operator_.value()) && !TokenTraits::isUnaryOp(operator_.value())) ||
operator_.value() == Token::Add;
bool isBinaryOnlyOperator = (TokenTraits::isBinaryOp(operator_.value()) && !TokenTraits::isUnaryOp(operator_.value()));
bool firstParameterMatchesUsingFor = parameterCount == 0 || *usingForType == *parameterTypes.front();
optional<string> wrongParametersMessage;
+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
@@ -1869,6 +1869,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