From f6543f772d3dbb02fb36cb603928b73ff2e8d648 Mon Sep 17 00:00:00 2001 From: wechman Date: Mon, 8 Aug 2022 14:14:39 +0200 Subject: [PATCH] Test for binding user type operator to error --- libsolidity/analysis/TypeChecker.cpp | 19 ------------------- .../operators/custom/bind_to_error.sol | 12 ++++++++++++ 2 files changed, 12 insertions(+), 19 deletions(-) create mode 100644 test/libsolidity/syntaxTests/operators/custom/bind_to_error.sol diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index eff7f3a3c..1948541a4 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -1750,25 +1750,6 @@ bool TypeChecker::visit(UnaryOperation const& _operation) solAssert(!builtinResult || !userDefinedOperatorResult); if (userDefinedOperatorResult) { - Type const* normalizedSubExprType = subExprType; - Type const* normalizedParameterType = userDefinedFunctionType->parameterTypes().front(); - - if (auto const* subExprReference = dynamic_cast(normalizedSubExprType)) - normalizedSubExprType = TypeProvider::withLocationIfReference(subExprReference->location(), normalizedSubExprType); - if (auto const* parameterReferenceType = dynamic_cast(normalizedParameterType)) - normalizedParameterType = TypeProvider::withLocationIfReference(parameterReferenceType->location(), normalizedParameterType); - - if (*normalizedSubExprType != *normalizedParameterType) - { - m_errorReporter.typeError( - 7983_error, - _operation.location(), - "User defined operator " + string(TokenTraits::toString(_operation.getOperator())) + - " needs a value of type " + - userDefinedFunctionType->parameterTypes().front()->humanReadableName() + "." - ); - } - _operation.annotation().type = subExprType; } else if (builtinResult) diff --git a/test/libsolidity/syntaxTests/operators/custom/bind_to_error.sol b/test/libsolidity/syntaxTests/operators/custom/bind_to_error.sol new file mode 100644 index 000000000..54a5123ff --- /dev/null +++ b/test/libsolidity/syntaxTests/operators/custom/bind_to_error.sol @@ -0,0 +1,12 @@ +type Int is int16; + +using {f as +} for IntError; + +error IntError(); + +function f(Int _a, Int _b) pure returns (Int) { + return Int.wrap(0); +} + +// ---- +// TypeError 5172: (39-47): Name has to refer to a user-defined value type, struct, enum or contract.