functions taking calldata args should be assignable to function pointers of same type

This commit is contained in:
nishant-sachdeva
2022-10-26 13:29:02 +05:30
parent 799ef0ab1a
commit 8c0740748e
5 changed files with 54 additions and 0 deletions
@@ -0,0 +1,10 @@
contract C {
function g(string calldata) external returns (bool) { return true; }
function main() external returns (bool) {
function (string memory) external returns (bool) ptr = this.g;
return ptr("testString");
}
}
// ----
// main() -> true
@@ -0,0 +1,14 @@
contract C {
function f(function (string calldata) external) external {}
function g(string calldata) external {}
function main() external {
function (string calldata) external ptr = this.g;
abi.encodeCall(this.f, (this.g));
this.f(this.g);
}
}
// ----
// TypeError 9574: (161-209): Type function (string memory) external is not implicitly convertible to expected type function (string calldata) external.
// TypeError 5407: (242-250): Cannot implicitly convert component at position 0 from "function (string memory) external" to "function (string calldata) external".
// TypeError 9553: (268-274): Invalid type for argument in function call. Invalid implicit conversion from function (string memory) external to function (string calldata) external requested.
@@ -0,0 +1,9 @@
contract C {
function g(string calldata) external {}
function main() view external {
function (string memory) external ptr = this.g;
ptr;
}
}
// ----
@@ -0,0 +1,9 @@
contract C {
function g(bytes calldata b) pure internal {}
function main() pure external {
function (bytes calldata) internal ptr = g;
ptr;
}
}
// ----