mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #8105 from ethereum/functionTypeRefactor
Add a new Function Type referring to FunctionDefinition's without calling context and use it to allow selector lookup.
This commit is contained in:
+20
@@ -0,0 +1,20 @@
|
||||
contract A {
|
||||
function f() external {}
|
||||
function g(uint256) external {}
|
||||
}
|
||||
contract B {
|
||||
function f() external returns (uint256) {}
|
||||
function g(uint256) external returns (uint256) {}
|
||||
}
|
||||
contract C {
|
||||
function test1() external returns(bytes4, bytes4, bytes4, bytes4) {
|
||||
return (A.f.selector, A.g.selector, B.f.selector, B.g.selector);
|
||||
}
|
||||
function test2() external returns(bytes4, bytes4, bytes4, bytes4) {
|
||||
A a; B b;
|
||||
return (a.f.selector, a.g.selector, b.f.selector, b.g.selector);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// test1() -> left(0x26121ff0), left(0xe420264a), left(0x26121ff0), left(0xe420264a)
|
||||
// test2() -> left(0x26121ff0), left(0xe420264a), left(0x26121ff0), left(0xe420264a)
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
contract A {
|
||||
function f() external {}
|
||||
function g() external pure {}
|
||||
}
|
||||
|
||||
contract B {
|
||||
function h() external {
|
||||
function() external f = A.f;
|
||||
function() external pure g = A.g;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (128-155): Type function A.f() is not implicitly convertible to expected type function () external.
|
||||
// TypeError: (165-197): Type function A.g() pure is not implicitly convertible to expected type function () pure external.
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
contract A {
|
||||
function f() external {}
|
||||
function g() external pure {}
|
||||
function h() public pure {}
|
||||
}
|
||||
|
||||
contract B {
|
||||
function i() external {
|
||||
A.f();
|
||||
A.g();
|
||||
A.h(); // might be allowed in the future
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (160-165): Cannot call function via contract name.
|
||||
// TypeError: (175-180): Cannot call function via contract name.
|
||||
// TypeError: (190-195): Cannot call function via contract name.
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
contract A {
|
||||
function f() external {}
|
||||
}
|
||||
|
||||
contract B {
|
||||
function g() external pure {
|
||||
A.f.selector;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
interface I {
|
||||
function f() external;
|
||||
}
|
||||
|
||||
contract B {
|
||||
function g() external pure {
|
||||
I.f.selector;
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
contract A {
|
||||
function f() internal {}
|
||||
}
|
||||
|
||||
contract B {
|
||||
function g() external {
|
||||
A.f;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (94-97): Member "f" not found or not visible after argument-dependent lookup in type(contract A).
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
contract A {
|
||||
function f() external {}
|
||||
function f(uint256) external {}
|
||||
}
|
||||
|
||||
contract B {
|
||||
function g() external {
|
||||
A.f;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (130-133): Member "f" not unique after argument-dependent lookup in type(contract A).
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
contract A {
|
||||
function f() private {}
|
||||
}
|
||||
|
||||
contract B {
|
||||
function g() external {
|
||||
A.f;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (93-96): Member "f" not found or not visible after argument-dependent lookup in type(contract A).
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
contract A {
|
||||
function f() public {}
|
||||
}
|
||||
|
||||
contract B {
|
||||
function g() external pure {
|
||||
A.f.selector;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user