From 5572d3aed84bf4039dbb5ebbd5aba6a58cf0aabd Mon Sep 17 00:00:00 2001 From: wechman Date: Mon, 29 Aug 2022 14:29:26 +0200 Subject: [PATCH] Adjustments after review --- Changelog.md | 2 +- libsolidity/analysis/ControlFlowBuilder.cpp | 4 ++-- libsolidity/analysis/ControlFlowGraph.cpp | 4 ++-- libsolidity/ast/AST.h | 2 +- libsolidity/codegen/ExpressionCompiler.cpp | 2 +- libsolidity/codegen/ir/IRGeneratorForStatements.cpp | 6 +++--- libsolidity/parsing/Parser.cpp | 2 +- .../localStorageVariables/ternary_assignment_fine.sol | 1 - 8 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Changelog.md b/Changelog.md index 3ac18f47c..3da4aa96f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,7 +5,7 @@ Language Features: Compiler Features: * Yul Optimizer: Allow replacing the previously hard-coded cleanup sequence by specifying custom steps after a colon delimiter (``:``) in the sequence string. - * Allow user-defined operators via ``using {f as +} for Typename;``. + * Allow defining custom operators for user-defined value types and structs via ``using {f as +} for Typename;`` syntax. Bugfixes: diff --git a/libsolidity/analysis/ControlFlowBuilder.cpp b/libsolidity/analysis/ControlFlowBuilder.cpp index 7797df958..e97520f16 100644 --- a/libsolidity/analysis/ControlFlowBuilder.cpp +++ b/libsolidity/analysis/ControlFlowBuilder.cpp @@ -97,7 +97,7 @@ bool ControlFlowBuilder::visit(BinaryOperation const& _operation) bool ControlFlowBuilder::visit(UnaryOperation const& _operation) { - solAssert(!!m_currentNode, ""); + solAssert(!!m_currentNode); if (_operation.annotation().userDefinedFunction) { @@ -112,7 +112,7 @@ bool ControlFlowBuilder::visit(UnaryOperation const& _operation) return true; } - return false; + return ASTConstVisitor::visit(_operation); } bool ControlFlowBuilder::visit(Conditional const& _conditional) diff --git a/libsolidity/analysis/ControlFlowGraph.cpp b/libsolidity/analysis/ControlFlowGraph.cpp index 14882743c..1df7b1f4b 100644 --- a/libsolidity/analysis/ControlFlowGraph.cpp +++ b/libsolidity/analysis/ControlFlowGraph.cpp @@ -29,8 +29,8 @@ using namespace solidity::frontend; FunctionDefinition const* CFGNode::resolveFunctionCall(ContractDefinition const* _mostDerivedContract) const { return std::visit(GenericVisitor{ - [=](FunctionCall const* _funCall) { return _funCall ? ASTNode::resolveFunctionCall(*_funCall, _mostDerivedContract) : nullptr; }, - [](FunctionDefinition const* _funDef) { return _funDef; } + [=](FunctionCall const* _call) { return _call ? ASTNode::resolveFunctionCall(*_call, _mostDerivedContract) : nullptr; }, + [](FunctionDefinition const* _definition) { return _definition; } }, functionCall); } diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h index a911186ab..7a9ced43c 100644 --- a/libsolidity/ast/AST.h +++ b/libsolidity/ast/AST.h @@ -656,7 +656,7 @@ private: * 2, this check is only done when a function is called. * * For version 4, T has to be user-defined value type or struct. All parameters and - * return value of all the functions has to be of type T. + * return value of all the functions have to be of type T. * * Finally, `using {f1, f2, ..., fn} for T global` is also valid at file level, as long as T is * a user-defined type defined in the same file at file level. In this case, the methods are diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 490ec3d1b..5767e7f13 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -573,7 +573,7 @@ bool ExpressionCompiler::visit(BinaryOperation const& _binaryOperation) return false; } - solAssert(!!_binaryOperation.annotation().commonType, ""); + solAssert(!!_binaryOperation.annotation().commonType); Type const* commonType = _binaryOperation.annotation().commonType; Token const c_op = _binaryOperation.getOperator(); diff --git a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp index 70b3aaf59..a373a922d 100644 --- a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp +++ b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp @@ -696,7 +696,7 @@ bool IRGeneratorForStatements::visit(UnaryOperation const& _unaryOperation) string argument = expressionAsType(_unaryOperation.subExpression(), *functionType->selfType()); solAssert(!argument.empty()); - solAssert(function->isImplemented(), ""); + solAssert(function->isImplemented()); solAssert( function->returnParameters().size() == 1, @@ -843,7 +843,7 @@ bool IRGeneratorForStatements::visit(BinaryOperation const& _binOp) string right = expressionAsType(_binOp.rightExpression(), *functionType->parameterTypes().at(0)); solAssert(!left.empty() && !right.empty()); - solAssert(function->isImplemented(), ""); + solAssert(function->isImplemented()); solAssert( function->returnParameters().size() == 1, @@ -860,7 +860,7 @@ bool IRGeneratorForStatements::visit(BinaryOperation const& _binOp) return false; } - solAssert(!!_binOp.annotation().commonType, ""); + solAssert(!!_binOp.annotation().commonType); Type const* commonType = _binOp.annotation().commonType; langutil::Token op = _binOp.getOperator(); diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index 7b2c8b18d..43d3fbca2 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -980,7 +980,7 @@ ASTPointer Parser::parseUsingDirective() { advance(); Token operator_ = m_scanner->currentToken(); - vector overridableOperators = { + vector static const overridableOperators = { // Potential future additions: <<, >>, **, ! Token::BitOr, Token::BitAnd, Token::BitXor, Token::Add, Token::Sub, Token::Mul, Token::Div, Token::Mod, diff --git a/test/libsolidity/syntaxTests/controlFlow/localStorageVariables/ternary_assignment_fine.sol b/test/libsolidity/syntaxTests/controlFlow/localStorageVariables/ternary_assignment_fine.sol index 435a01613..10e9a6795 100644 --- a/test/libsolidity/syntaxTests/controlFlow/localStorageVariables/ternary_assignment_fine.sol +++ b/test/libsolidity/syntaxTests/controlFlow/localStorageVariables/ternary_assignment_fine.sol @@ -6,5 +6,4 @@ contract C { y; } } - // ----