Skip to content

Commit a866aae

Browse files
committed
Refactor several error messages in TypeChecker to use fmtlib
1 parent 6da09e8 commit a866aae

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

libsolidity/analysis/TypeChecker.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#include <boost/algorithm/string/join.hpp>
4141
#include <boost/algorithm/string/predicate.hpp>
4242

43+
#include <fmt/format.h>
44+
4345
#include <range/v3/algorithm/count_if.hpp>
4446
#include <range/v3/view/drop_exactly.hpp>
4547
#include <range/v3/view/enumerate.hpp>
@@ -1731,7 +1733,13 @@ bool TypeChecker::visit(UnaryOperation const& _operation)
17311733
TypeResult result = type(_operation.subExpression())->unaryOperatorResult(op);
17321734
if (!result)
17331735
{
1734-
string description = "Built-in unary operator " + string(TokenTraits::toString(op)) + " cannot be applied to type " + subExprType->humanReadableName() + "." + (!result.message().empty() ? " " + result.message() : "");
1736+
string description = fmt::format(
1737+
"Built-in unary operator {} cannot be applied to type {}.{}",
1738+
TokenTraits::toString(op),
1739+
subExprType->humanReadableName(),
1740+
!result.message().empty() ? " " + result.message() : ""
1741+
);
1742+
17351743
if (modifying)
17361744
// Cannot just report the error, ignore the unary operator, and continue,
17371745
// because the sub-expression was already processed with requireLValue()
@@ -3796,9 +3804,11 @@ void TypeChecker::endVisit(UsingForDirective const& _usingFor)
37963804
m_errorReporter.fatalTypeError(
37973805
4731_error,
37983806
path->location(),
3799-
"The function \"" + joinHumanReadable(path->path(), ".") + "\" " +
3800-
"does not have any parameters, and therefore cannot be bound to the type \"" +
3801-
(normalizedType ? normalizedType->toString(true /* withoutDataLocation */) : "*") + "\"."
3807+
fmt::format(
3808+
"The function \"{}\" does not have any parameters, and therefore cannot be bound to the type \"{}\".",
3809+
joinHumanReadable(path->path(), "."),
3810+
normalizedType ? normalizedType->toString(true /* withoutDataLocation */) : "*"
3811+
)
38023812
);
38033813

38043814
FunctionType const* functionType = dynamic_cast<FunctionType const&>(*functionDefinition.type()).asBoundFunction();
@@ -3810,14 +3820,13 @@ void TypeChecker::endVisit(UsingForDirective const& _usingFor)
38103820
m_errorReporter.typeError(
38113821
3100_error,
38123822
path->location(),
3813-
"The function \"" + joinHumanReadable(path->path(), ".") + "\" "+
3814-
"cannot be bound to the type \"" + _usingFor.typeName()->annotation().type->toString(true /* withoutDataLocation */) +
3815-
"\" because the type cannot be implicitly converted to the first argument" +
3816-
" of the function (\"" + functionType->selfType()->humanReadableName() + "\")" +
3817-
(
3818-
result.message().empty() ?
3819-
"." :
3820-
": " + result.message()
3823+
fmt::format(
3824+
"The function \"{}\" cannot be bound to the type \"{}\" because the type cannot "
3825+
"be implicitly converted to the first argument of the function (\"{}\"){}",
3826+
joinHumanReadable(path->path(), "."),
3827+
_usingFor.typeName()->annotation().type->toString(true /* withoutDataLocation */),
3828+
functionType->selfType()->humanReadableName(),
3829+
result.message().empty() ? "." : ": " + result.message()
38213830
)
38223831
);
38233832
}

0 commit comments

Comments
 (0)