diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index ce5b2c255..a8b644125 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -1731,24 +1731,24 @@ bool TypeChecker::visit(UnaryOperation const& _operation) // Check if the operator is built-in or user-defined. - FunctionDefinition const* userDefinedOperator = subExprType->userDefinedOperator( + Result userDefinedOperatorResult = subExprType->userDefinedOperator( _operation.getOperator(), *currentDefinitionScope(), true // _unaryOperation ); - _operation.annotation().userDefinedFunction = userDefinedOperator; + _operation.annotation().userDefinedFunction = userDefinedOperatorResult; FunctionType const* userDefinedFunctionType = nullptr; - if (userDefinedOperator) + if (userDefinedOperatorResult) userDefinedFunctionType = &dynamic_cast( - userDefinedOperator->libraryFunction() ? - *userDefinedOperator->typeViaContractName() : - *userDefinedOperator->type() + userDefinedOperatorResult.get()->libraryFunction() ? + *userDefinedOperatorResult.get()->typeViaContractName() : + *userDefinedOperatorResult.get()->type() ); TypeResult builtinResult = subExprType->unaryOperatorResult(op); - solAssert(!builtinResult || !userDefinedOperator); - if (userDefinedOperator) + solAssert(!builtinResult || !userDefinedOperatorResult); + if (userDefinedOperatorResult) { solAssert(userDefinedFunctionType->parameterTypes().size() == 1); solAssert(userDefinedFunctionType->returnParameterTypes().size() == 1); @@ -1762,7 +1762,10 @@ bool TypeChecker::visit(UnaryOperation const& _operation) _operation.annotation().type = builtinResult; else { - string description = "Unary operator " + string(TokenTraits::toString(op)) + " cannot be applied to type " + subExprType->humanReadableName() + "." + (!builtinResult.message().empty() ? " " + builtinResult.message() : ""); + string description = + "Unary operator " + string(TokenTraits::toString(op)) + " cannot be applied to type " + subExprType->humanReadableName() + "." + + (!builtinResult.message().empty() ? " " + builtinResult.message() : "") + + (!userDefinedOperatorResult.message().empty() ? " " + userDefinedOperatorResult.message() : ""); if (modifying) // Cannot just report the error, ignore the unary operator, and continue, // because the sub-expression was already processed with requireLValue() diff --git a/test/libsolidity/syntaxTests/operators/custom/operator_invalid_return_parameters.sol b/test/libsolidity/syntaxTests/operators/custom/operator_invalid_return_parameters.sol index 7a97461da..c8ad3b8dd 100644 --- a/test/libsolidity/syntaxTests/operators/custom/operator_invalid_return_parameters.sol +++ b/test/libsolidity/syntaxTests/operators/custom/operator_invalid_return_parameters.sol @@ -44,6 +44,6 @@ function f() pure { // TypeError 7995: (90-92): The function "lt" needs to return exactly one value of type bool to be used for the operator <. // TypeError 2271: (492-517): Operator + not compatible with types Int and Int. No matching user-defined operator found. // TypeError 2271: (523-548): Operator / not compatible with types Int and Int. No matching user-defined operator found. -// TypeError 4907: (554-566): Unary operator - cannot be applied to type Int +// TypeError 4907: (554-566): Unary operator - cannot be applied to type Int. No matching user-defined operator found. // TypeError 2271: (572-597): Operator < not compatible with types Int and Int. No matching user-defined operator found. // TypeError 2271: (603-628): Operator > not compatible with types Int and Int. No matching user-defined operator found. diff --git a/test/libsolidity/syntaxTests/operators/custom/unary_operator_attached_to_two_arguments_function.sol b/test/libsolidity/syntaxTests/operators/custom/unary_operator_attached_to_two_argument_function.sol similarity index 87% rename from test/libsolidity/syntaxTests/operators/custom/unary_operator_attached_to_two_arguments_function.sol rename to test/libsolidity/syntaxTests/operators/custom/unary_operator_attached_to_two_argument_function.sol index 02c6e8eb8..beb04264c 100644 --- a/test/libsolidity/syntaxTests/operators/custom/unary_operator_attached_to_two_arguments_function.sol +++ b/test/libsolidity/syntaxTests/operators/custom/unary_operator_attached_to_two_argument_function.sol @@ -15,4 +15,4 @@ contract C { // ---- // TypeError 1147: (32-38): The function "bitnot" needs to have exactly one parameter to be used for the operator ~. -// TypeError 4907: (186-198): Unary operator ~ cannot be applied to type Int +// TypeError 4907: (186-198): Unary operator ~ cannot be applied to type Int. No matching user-defined operator found.