Skip to content

Commit b66cea1

Browse files
authored
Merge pull request #13660 from ethereum/operator-releated-error-message-tweaks
Operator-releated error message tweaks
2 parents 2cc6610 + a866aae commit b66cea1

File tree

78 files changed

+217
-197
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+217
-197
lines changed

libsolidity/analysis/DeclarationTypeChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ void DeclarationTypeChecker::endVisit(UserDefinedTypeName const& _typeName)
190190
m_errorReporter.fatalTypeError(
191191
5172_error,
192192
_typeName.location(),
193-
"Name has to refer to a struct, enum or contract."
193+
"Name has to refer to a user-defined type."
194194
);
195195
}
196196
}

libsolidity/analysis/TypeChecker.cpp

Lines changed: 23 additions & 14 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 = "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()
@@ -1760,9 +1768,9 @@ void TypeChecker::endVisit(BinaryOperation const& _operation)
17601768
m_errorReporter.typeError(
17611769
2271_error,
17621770
_operation.location(),
1763-
"Operator " +
1771+
"Built-in binary operator " +
17641772
string(TokenTraits::toString(_operation.getOperator())) +
1765-
" not compatible with types " +
1773+
" cannot be applied to types " +
17661774
leftType->humanReadableName() +
17671775
" and " +
17681776
rightType->humanReadableName() + "." +
@@ -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->humanReadableName() : "*") + "\"."
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->humanReadableName() +
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
}

test/libsolidity/syntaxTests/abiEncoder/abi_encodeCall_tuple_from_invalid_operator.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ contract C {
1515
}
1616
}
1717
// ----
18-
// TypeError 2271: (284-299): Operator + not compatible with types tuple(int_const 1,int_const 1) and tuple(int_const 2,int_const 2).
18+
// TypeError 2271: (284-299): Built-in binary operator + cannot be applied to types tuple(int_const 1,int_const 1) and tuple(int_const 2,int_const 2).
1919
// TypeError 9062: (284-299): Expected an inline tuple, not an expression of a tuple type.
20-
// TypeError 2271: (334-345): Operator / not compatible with types tuple() and tuple().
20+
// TypeError 2271: (334-345): Built-in binary operator / cannot be applied to types tuple() and tuple().
2121
// TypeError 9062: (334-345): Expected an inline tuple, not an expression of a tuple type.
22-
// TypeError 4907: (380-383): Unary operator ! cannot be applied to type tuple().
22+
// TypeError 4907: (380-383): Built-in unary operator ! cannot be applied to type tuple().
2323
// TypeError 9062: (380-383): Expected an inline tuple, not an expression of a tuple type.

test/libsolidity/syntaxTests/conversion/implicit_conversion_of_super_in_comparison.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ contract C {
1919
}
2020
}
2121
// ----
22-
// TypeError 2271: (144-157): Operator != not compatible with types type(contract super C) and contract C.
23-
// TypeError 2271: (167-180): Operator != not compatible with types contract C and type(contract super C).
24-
// TypeError 2271: (254-264): Operator != not compatible with types type(contract super C) and contract C.
25-
// TypeError 2271: (274-284): Operator != not compatible with types contract C and type(contract super C).
26-
// TypeError 2271: (349-359): Operator != not compatible with types type(contract super C) and contract D.
27-
// TypeError 2271: (369-379): Operator != not compatible with types contract D and type(contract super C).
22+
// TypeError 2271: (144-157): Built-in binary operator != cannot be applied to types type(contract super C) and contract C.
23+
// TypeError 2271: (167-180): Built-in binary operator != cannot be applied to types contract C and type(contract super C).
24+
// TypeError 2271: (254-264): Built-in binary operator != cannot be applied to types type(contract super C) and contract C.
25+
// TypeError 2271: (274-284): Built-in binary operator != cannot be applied to types contract C and type(contract super C).
26+
// TypeError 2271: (349-359): Built-in binary operator != cannot be applied to types type(contract super C) and contract D.
27+
// TypeError 2271: (369-379): Built-in binary operator != cannot be applied to types contract D and type(contract super C).

test/libsolidity/syntaxTests/conversion/implicit_conversion_of_super_in_operators.sol

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,25 @@ contract C {
3030
}
3131
}
3232
// ----
33-
// TypeError 2271: (49-62): Operator << not compatible with types type(contract super C) and contract C.
34-
// TypeError 2271: (72-85): Operator >> not compatible with types type(contract super C) and contract C.
35-
// TypeError 2271: (95-107): Operator ^ not compatible with types type(contract super C) and contract C.
36-
// TypeError 2271: (117-129): Operator | not compatible with types type(contract super C) and contract C.
37-
// TypeError 2271: (139-151): Operator & not compatible with types type(contract super C) and contract C.
38-
// TypeError 2271: (162-174): Operator * not compatible with types type(contract super C) and contract C.
39-
// TypeError 2271: (184-196): Operator / not compatible with types type(contract super C) and contract C.
40-
// TypeError 2271: (206-218): Operator % not compatible with types type(contract super C) and contract C.
41-
// TypeError 2271: (228-240): Operator - not compatible with types type(contract super C) and contract C.
42-
// TypeError 2271: (250-262): Operator + not compatible with types type(contract super C) and contract C.
43-
// TypeError 2271: (272-285): Operator ** not compatible with types type(contract super C) and contract C.
44-
// TypeError 2271: (296-309): Operator == not compatible with types type(contract super C) and contract C.
45-
// TypeError 2271: (319-332): Operator != not compatible with types type(contract super C) and contract C.
46-
// TypeError 2271: (342-355): Operator >= not compatible with types type(contract super C) and contract C.
47-
// TypeError 2271: (365-378): Operator <= not compatible with types type(contract super C) and contract C.
48-
// TypeError 2271: (388-400): Operator < not compatible with types type(contract super C) and contract C.
49-
// TypeError 2271: (410-422): Operator > not compatible with types type(contract super C) and contract C.
50-
// TypeError 2271: (433-446): Operator || not compatible with types type(contract super C) and contract C.
51-
// TypeError 2271: (456-469): Operator && not compatible with types type(contract super C) and contract C.
33+
// TypeError 2271: (49-62): Built-in binary operator << cannot be applied to types type(contract super C) and contract C.
34+
// TypeError 2271: (72-85): Built-in binary operator >> cannot be applied to types type(contract super C) and contract C.
35+
// TypeError 2271: (95-107): Built-in binary operator ^ cannot be applied to types type(contract super C) and contract C.
36+
// TypeError 2271: (117-129): Built-in binary operator | cannot be applied to types type(contract super C) and contract C.
37+
// TypeError 2271: (139-151): Built-in binary operator & cannot be applied to types type(contract super C) and contract C.
38+
// TypeError 2271: (162-174): Built-in binary operator * cannot be applied to types type(contract super C) and contract C.
39+
// TypeError 2271: (184-196): Built-in binary operator / cannot be applied to types type(contract super C) and contract C.
40+
// TypeError 2271: (206-218): Built-in binary operator % cannot be applied to types type(contract super C) and contract C.
41+
// TypeError 2271: (228-240): Built-in binary operator - cannot be applied to types type(contract super C) and contract C.
42+
// TypeError 2271: (250-262): Built-in binary operator + cannot be applied to types type(contract super C) and contract C.
43+
// TypeError 2271: (272-285): Built-in binary operator ** cannot be applied to types type(contract super C) and contract C.
44+
// TypeError 2271: (296-309): Built-in binary operator == cannot be applied to types type(contract super C) and contract C.
45+
// TypeError 2271: (319-332): Built-in binary operator != cannot be applied to types type(contract super C) and contract C.
46+
// TypeError 2271: (342-355): Built-in binary operator >= cannot be applied to types type(contract super C) and contract C.
47+
// TypeError 2271: (365-378): Built-in binary operator <= cannot be applied to types type(contract super C) and contract C.
48+
// TypeError 2271: (388-400): Built-in binary operator < cannot be applied to types type(contract super C) and contract C.
49+
// TypeError 2271: (410-422): Built-in binary operator > cannot be applied to types type(contract super C) and contract C.
50+
// TypeError 2271: (433-446): Built-in binary operator || cannot be applied to types type(contract super C) and contract C.
51+
// TypeError 2271: (456-469): Built-in binary operator && cannot be applied to types type(contract super C) and contract C.
5252
// TypeError 4247: (480-485): Expression has to be an lvalue.
5353
// TypeError 7366: (480-493): Operator -= not compatible with types type(contract super C) and contract C.
5454
// TypeError 4247: (503-508): Expression has to be an lvalue.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
error E(uint);
22
function f(E x) pure returns (uint) {}
33
// ----
4-
// TypeError 5172: (26-27): Name has to refer to a struct, enum or contract.
4+
// TypeError 5172: (26-27): Name has to refer to a user-defined type.

test/libsolidity/syntaxTests/errors/error_incompatible_binary_ops.sol

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@ contract C {
2727
}
2828

2929
// ----
30-
// TypeError 2271: (86-116): Operator << not compatible with types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
31-
// TypeError 2271: (126-156): Operator >> not compatible with types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
32-
// TypeError 2271: (166-195): Operator ^ not compatible with types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
33-
// TypeError 2271: (205-234): Operator | not compatible with types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
34-
// TypeError 2271: (244-273): Operator & not compatible with types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
35-
// TypeError 2271: (284-313): Operator * not compatible with types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
36-
// TypeError 2271: (323-352): Operator / not compatible with types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
37-
// TypeError 2271: (362-391): Operator % not compatible with types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
38-
// TypeError 2271: (401-430): Operator + not compatible with types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
39-
// TypeError 2271: (440-469): Operator - not compatible with types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
40-
// TypeError 2271: (480-510): Operator == not compatible with types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
41-
// TypeError 2271: (520-550): Operator != not compatible with types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
42-
// TypeError 2271: (560-590): Operator >= not compatible with types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
43-
// TypeError 2271: (600-630): Operator <= not compatible with types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
44-
// TypeError 2271: (640-669): Operator < not compatible with types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
45-
// TypeError 2271: (679-708): Operator > not compatible with types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
46-
// TypeError 2271: (719-749): Operator || not compatible with types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
47-
// TypeError 2271: (759-789): Operator && not compatible with types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
30+
// TypeError 2271: (86-116): Built-in binary operator << cannot be applied to types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
31+
// TypeError 2271: (126-156): Built-in binary operator >> cannot be applied to types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
32+
// TypeError 2271: (166-195): Built-in binary operator ^ cannot be applied to types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
33+
// TypeError 2271: (205-234): Built-in binary operator | cannot be applied to types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
34+
// TypeError 2271: (244-273): Built-in binary operator & cannot be applied to types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
35+
// TypeError 2271: (284-313): Built-in binary operator * cannot be applied to types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
36+
// TypeError 2271: (323-352): Built-in binary operator / cannot be applied to types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
37+
// TypeError 2271: (362-391): Built-in binary operator % cannot be applied to types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
38+
// TypeError 2271: (401-430): Built-in binary operator + cannot be applied to types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
39+
// TypeError 2271: (440-469): Built-in binary operator - cannot be applied to types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
40+
// TypeError 2271: (480-510): Built-in binary operator == cannot be applied to types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
41+
// TypeError 2271: (520-550): Built-in binary operator != cannot be applied to types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
42+
// TypeError 2271: (560-590): Built-in binary operator >= cannot be applied to types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
43+
// TypeError 2271: (600-630): Built-in binary operator <= cannot be applied to types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
44+
// TypeError 2271: (640-669): Built-in binary operator < cannot be applied to types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
45+
// TypeError 2271: (679-708): Built-in binary operator > cannot be applied to types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
46+
// TypeError 2271: (719-749): Built-in binary operator || cannot be applied to types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).
47+
// TypeError 2271: (759-789): Built-in binary operator && cannot be applied to types error MyCustomError(uint256,bool) and error MyCustomError(uint256,bool).

test/libsolidity/syntaxTests/errors/error_incompatible_unary_operator.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ contract C {
88

99
// ----
1010
// TypeError 4247: (86-99): Expression has to be an lvalue.
11-
// TypeError 9767: (86-101): Unary operator ++ cannot be applied to type error MyCustomError(uint256,bool).
11+
// TypeError 9767: (86-101): Built-in unary operator ++ cannot be applied to type error MyCustomError(uint256,bool).

test/libsolidity/syntaxTests/errors/using_2.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ contract C {
99
}
1010
}
1111
// ----
12-
// TypeError 5172: (91-92): Name has to refer to a struct, enum or contract.
12+
// TypeError 5172: (91-92): Name has to refer to a user-defined type.

test/libsolidity/syntaxTests/errors/weird3.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ contract C {
44
E x;
55
}
66
// ----
7-
// TypeError 5172: (29-30): Name has to refer to a struct, enum or contract.
7+
// TypeError 5172: (29-30): Name has to refer to a user-defined type.

0 commit comments

Comments
 (0)