Skip to content

Commit

Permalink
Parser: Fix spuriously emitted parser error for unary plus operations…
Browse files Browse the repository at this point in the history
… when used as binary operator in some cases
  • Loading branch information
clonker committed Aug 5, 2024
1 parent 7094e30 commit 57ab4dc
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Compiler Features:


Bugfixes:
* Parser: Fix spuriously emitted parser error for unary plus operations when used as binary operator in some cases.
* SMTChecker: Fix error that reports invalid number of verified checks for BMC and CHC engines.
* SMTChecker: Fix formatting of unary minus expressions in invariants.
* SMTChecker: Fix internal compiler error when reporting proved targets for BMC engine.
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/parsing/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2152,7 +2152,7 @@ ASTPointer<Expression> Parser::parseUnaryExpression(
ASTNodeFactory(*this, _partiallyParsedExpression) : ASTNodeFactory(*this);
Token token = m_scanner->currentToken();

if (token == Token::Add)
if (!_partiallyParsedExpression && token == Token::Add)
fatalParserError(9636_error, "Use of unary + is disallowed.");

if (!_partiallyParsedExpression && (TokenTraits::isUnaryOp(token) || TokenTraits::isCountOp(token)))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
contract C
{
function f(int x) public
{
(x /= 1) + +(1,1);
}
}
// ----
// ParserError 9636: (67-68): Use of unary + is disallowed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
contract C {
function f(int32 x) external pure returns (int32)
{
this.x + 1;
return x;
}
}
// ----
// TypeError 9582: (81-87): Member "x" not found or not visible after argument-dependent lookup in contract C.
12 changes: 12 additions & 0 deletions test/libsolidity/syntaxTests/types/binary_add_op.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
contract C {
function f(int32 x) external pure returns (int32)
{
x = 1 + 1;
(x /= 1) + 1;
(x = ++x) + 1;
(0) + 1;
return x;
}
}
// ----
// Warning 6133: (145-152): Statement has no effect.

0 comments on commit 57ab4dc

Please sign in to comment.