Skip to content

Commit 1827df8

Browse files
Merge pull request #12779 from nishant-sachdeva/distinguish_different_types_in_error_messages_from_abiEncodecall
Error messages from abi encodecall are giving more details about the types of the involved variables
2 parents c13e611 + 624d2d3 commit 1827df8

6 files changed

+52
-3
lines changed

libsolidity/analysis/TypeChecker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2204,9 +2204,9 @@ void TypeChecker::typeCheckABIEncodeCallFunction(FunctionCall const& _functionCa
22042204
"Cannot implicitly convert component at position " +
22052205
to_string(i) +
22062206
" from \"" +
2207-
argType.canonicalName() +
2207+
argType.toString() +
22082208
"\" to \"" +
2209-
functionPointerType->parameterTypes()[i]->canonicalName() +
2209+
functionPointerType->parameterTypes()[i]->toString() +
22102210
"\"" +
22112211
(result.message().empty() ? "." : ": " + result.message())
22122212
);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
interface I {
2+
function f(address payable) external;
3+
}
4+
5+
contract C {
6+
function main() external view {
7+
abi.encodeCall(I.f, (address(0)));
8+
}
9+
}
10+
// ----
11+
// TypeError 5407: (136-148): Cannot implicitly convert component at position 0 from "address" to "address payable".
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
interface I {
2+
function f(function (string calldata) external) external;
3+
}
4+
5+
contract C {
6+
function g(string calldata) external {}
7+
8+
function main() external view {
9+
abi.encodeCall(I.f, (this.g));
10+
}
11+
}
12+
// ----
13+
// TypeError 5407: (201-209): Cannot implicitly convert component at position 0 from "function (string memory) external" to "function (string calldata) external".
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
interface I {
2+
function f(function (string calldata) external view returns (uint)) external;
3+
}
4+
5+
contract C {
6+
function g(string memory) external {}
7+
8+
function main() external view {
9+
abi.encodeCall(I.f, (this.g));
10+
}
11+
}
12+
// ----
13+
// TypeError 5407: (219-227): Cannot implicitly convert component at position 0 from "function (string memory) external" to "function (string calldata) view external returns (uint256)".
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
interface I {
2+
function f(string calldata) external;
3+
}
4+
5+
contract C {
6+
string s;
7+
function main() external view {
8+
abi.encodeCall(I.f, (s));
9+
}
10+
}
11+
// ----
12+
// TypeError 5407: (150-153): Cannot implicitly convert component at position 0 from "string storage ref" to "string calldata".

test/libsolidity/syntaxTests/specialFunctions/encodeCall_fail_args.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ contract C {
2424
// TypeError 7788: (382-408): Expected 1 instead of 0 components for the tuple parameter.
2525
// TypeError 6219: (489-511): Expected two arguments: a function pointer followed by a tuple.
2626
// TypeError 7515: (597-628): Expected a tuple with 2 components instead of a single non-tuple parameter.
27-
// TypeError 5407: (621-627): Cannot implicitly convert component at position 0 from "uint8[2]" to "int256".
27+
// TypeError 5407: (621-627): Cannot implicitly convert component at position 0 from "uint8[2] memory" to "int256".

0 commit comments

Comments
 (0)