From 6724455b1633d6f7537f1820d2953562a3e4db73 Mon Sep 17 00:00:00 2001 From: wechman Date: Fri, 23 Sep 2022 13:49:14 +0200 Subject: [PATCH] Merge type errors 8112 and 7617. --- libsolidity/analysis/TypeChecker.cpp | 19 ++++--------------- .../custom/operator_invalid_parameters.sol | 2 +- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 9528fe931..bd9c61a94 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -3992,6 +3992,9 @@ void TypeChecker::endVisit(UsingForDirective const& _usingFor) *TypeProvider::withLocationIfReference(DataLocation::Storage, parameterTypes.at(0)) != *TypeProvider::withLocationIfReference(DataLocation::Storage, usingForType) ) + ) || + ( + parameterCount != 1 && parameterCount != 2 ) ) m_errorReporter.typeError( @@ -3999,25 +4002,11 @@ void TypeChecker::endVisit(UsingForDirective const& _usingFor) path->location(), "The function \"" + joinHumanReadable(path->path(), ".") + "\" "+ "needs to have one or two parameters of type " + - _usingFor.typeName()->annotation().type->canonicalName() + + usingForType->canonicalName() + " and the same data location to be used for the operator " + TokenTraits::friendlyName(*operator_) + "." ); - else if ( - parameterCount != 1 && - parameterCount != 2 - ) - m_errorReporter.typeError( - 8112_error, - path->location(), - "The function \"" + joinHumanReadable(path->path(), ".") + "\" "+ - "needs to have one or two parameters of type " + - _usingFor.typeName()->annotation().type->canonicalName() + - " and the same data location to be used for the operator " + - TokenTraits::friendlyName(*operator_) + - "." - ); TypePointers const& returnParameterTypes = functionType->returnParameterTypes(); size_t const returnParameterCount = returnParameterTypes.size(); diff --git a/test/libsolidity/syntaxTests/operators/custom/operator_invalid_parameters.sol b/test/libsolidity/syntaxTests/operators/custom/operator_invalid_parameters.sol index 96266730b..c98b19b44 100644 --- a/test/libsolidity/syntaxTests/operators/custom/operator_invalid_parameters.sol +++ b/test/libsolidity/syntaxTests/operators/custom/operator_invalid_parameters.sol @@ -26,7 +26,7 @@ function f() pure { // ---- // TypeError 1884: (33-36): The function "add" needs to have two parameters of type Int and the same data location to be used for the operator +. -// TypeError 8112: (47-50): The function "sub" needs to have one or two parameters of type Int and the same data location to be used for the operator -. +// TypeError 7617: (47-50): The function "sub" needs to have one or two parameters of type Int and the same data location to be used for the operator -. // TypeError 7617: (61-64): The function "div" needs to have one or two parameters of type Int and the same data location to be used for the operator /. // TypeError 3605: (61-64): The function "div" needs to have parameters and return value of the same type to be used for the operator /. // TypeError 2271: (325-350): Built-in binary operator + cannot be applied to types Int and Int. No matching user-defined operator found.