mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Mark function selector accesses as pure for pure expressions and mark function accesses via contract name as pure.
This commit is contained in:
@@ -3,9 +3,9 @@ contract B {
|
||||
function g() public {}
|
||||
}
|
||||
contract C is B {
|
||||
function h() public {
|
||||
B.f.selector;
|
||||
B.g.selector;
|
||||
function h() public returns (bytes4 fs, bytes4 gs) {
|
||||
fs = B.f.selector;
|
||||
gs = B.g.selector;
|
||||
B.g();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@ contract A {
|
||||
}
|
||||
|
||||
contract B {
|
||||
function g() external pure {
|
||||
A.f.selector;
|
||||
function g() external pure returns(bytes4) {
|
||||
return A.f.selector;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@ interface I {
|
||||
}
|
||||
|
||||
contract B {
|
||||
function g() external pure {
|
||||
I.f.selector;
|
||||
function g() external pure returns(bytes4) {
|
||||
return I.f.selector;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@ contract A {
|
||||
}
|
||||
|
||||
contract B {
|
||||
function g() external pure {
|
||||
A.f.selector;
|
||||
function g() external pure returns(bytes4) {
|
||||
return A.f.selector;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
interface Banana {
|
||||
function transfer(address,uint256) external returns(bool);
|
||||
}
|
||||
|
||||
contract Apple {
|
||||
function f() public pure {
|
||||
Banana.transfer;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (141-156): Statement has no effect.
|
||||
@@ -0,0 +1,14 @@
|
||||
interface A {
|
||||
function f() external;
|
||||
}
|
||||
contract B {
|
||||
function g() public {}
|
||||
}
|
||||
|
||||
contract C is B {
|
||||
function h() external {}
|
||||
bytes4 constant s1 = A.f.selector;
|
||||
bytes4 constant s2 = B.g.selector;
|
||||
bytes4 constant s3 = this.h.selector;
|
||||
bytes4 constant s4 = super.g.selector;
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
contract C {
|
||||
function f() public pure returns (bytes4) {
|
||||
function() external g;
|
||||
// Make sure g.selector is not considered pure:
|
||||
// If it was considered pure, this would emit a warning "Statement has no effect".
|
||||
g.selector;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
contract A {
|
||||
function() external public f;
|
||||
}
|
||||
|
||||
contract C {
|
||||
bytes4 constant s4 = A.f.selector;
|
||||
}
|
||||
// ----
|
||||
// TypeError: (88-91): Member "f" not found or not visible after argument-dependent lookup in type(contract A).
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
contract A {
|
||||
function() external public f;
|
||||
}
|
||||
contract B {
|
||||
function() external public g;
|
||||
}
|
||||
|
||||
contract C is B {
|
||||
function() external public h;
|
||||
bytes4 constant s1 = h.selector;
|
||||
bytes4 constant s2 = B.g.selector;
|
||||
bytes4 constant s3 = this.h.selector;
|
||||
}
|
||||
// ----
|
||||
// TypeError: (176-186): Initial value for constant variable has to be compile-time constant.
|
||||
// TypeError: (213-225): Initial value for constant variable has to be compile-time constant.
|
||||
// TypeError: (252-267): Initial value for constant variable has to be compile-time constant.
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
contract B {
|
||||
function() external public g;
|
||||
}
|
||||
|
||||
contract C is B {
|
||||
bytes4 constant s4 = super.g.selector;
|
||||
}
|
||||
// ----
|
||||
// TypeError: (93-100): Member "g" not found or not visible after argument-dependent lookup in contract super C.
|
||||
Reference in New Issue
Block a user