From 5cf6fa84ace58e9fa0fef2a7fc40e531c56acb24 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 14 Jun 2018 16:08:59 +0200 Subject: Provide better suggestions in error messages with respect to call and hash functions. --- libsolidity/analysis/TypeChecker.cpp | 38 ++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index ab6b46f4..9c4e9021 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -1781,6 +1781,23 @@ bool TypeChecker::visit(FunctionCall const& _functionCall) for (auto const& member: membersRemovedForStructConstructor) msg += " " + member; } + else if ( + functionType->kind() == FunctionType::Kind::BareCall || + functionType->kind() == FunctionType::Kind::BareCallCode || + functionType->kind() == FunctionType::Kind::BareDelegateCall + ) + { + if (arguments.empty()) + msg += " This function requires a single bytes argument. Use \"\" as argument to provide empty calldata."; + else + msg += " This function requires a single bytes argument. If all your arguments are value types, you can use abi.encode(...) to properly generate it."; + } + else if ( + functionType->kind() == FunctionType::Kind::SHA3 || + functionType->kind() == FunctionType::Kind::SHA256 || + functionType->kind() == FunctionType::Kind::RIPEMD160 + ) + msg += " This function requires a single bytes argument. Use abi.encodePacked(...) to properly encode the values."; m_errorReporter.typeError(_functionCall.location(), msg); } else if (isPositionalCall) @@ -1817,15 +1834,28 @@ bool TypeChecker::visit(FunctionCall const& _functionCall) } } else if (!type(*arguments[i])->isImplicitlyConvertibleTo(*parameterTypes[i])) - m_errorReporter.typeError( - arguments[i]->location(), + { + string msg = "Invalid type for argument in function call. " "Invalid implicit conversion from " + type(*arguments[i])->toString() + " to " + parameterTypes[i]->toString() + - " requested." - ); + " requested."; + if ( + functionType->kind() == FunctionType::Kind::BareCall || + functionType->kind() == FunctionType::Kind::BareCallCode || + functionType->kind() == FunctionType::Kind::BareDelegateCall + ) + msg += " This function requires a single bytes argument. If all your arguments are value types, you can use abi.encode(...) to properly generate it."; + else if ( + functionType->kind() == FunctionType::Kind::SHA3 || + functionType->kind() == FunctionType::Kind::SHA256 || + functionType->kind() == FunctionType::Kind::RIPEMD160 + ) + msg += " This function requires a single bytes argument. Use abi.encodePacked(...) to properly encode the values."; + m_errorReporter.typeError(arguments[i]->location(), msg); + } } } else -- cgit v1.2.3