Set state mutability of function type members `gas and value` to pure.

This commit is contained in:
Daniel Kirchner
2019-06-13 18:27:53 +02:00
parent 668972bb4e
commit 4d38df6920
6 changed files with 59 additions and 2 deletions
@@ -0,0 +1,13 @@
contract C {
function f() external payable {}
function g(address a) external pure {
a.call.value(42);
a.call.gas(42);
a.staticcall.gas(42);
a.delegatecall.gas(42);
}
function h() external view {
this.f.value(42);
this.f.gas(42);
}
}
@@ -0,0 +1,16 @@
contract C {
function f(address a) external view returns (bool success) {
(success,) = a.call.gas(42)("");
}
function g(address a) external view returns (bool success) {
(success,) = a.call.gas(42)("");
}
function h() external payable {}
function i() external view {
this.h.gas(42)();
}
}
// ----
// TypeError: (90-108): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable.
// TypeError: (190-208): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable.
// TypeError: (279-295): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable.
@@ -0,0 +1,11 @@
contract C {
function f() external view {}
function test(address a) external view returns (bool status) {
// This used to incorrectly raise an error about violating the view mutability.
(status,) = a.staticcall.gas(42)("");
this.f.gas(42)();
}
}
// ====
// EVMVersion: >=byzantium
// ----
@@ -0,0 +1,16 @@
contract C {
function f(address a) external view returns (bool success) {
(success,) = a.call.value(42)("");
}
function g(address a) external view returns (bool success) {
(success,) = a.call.value(42)("");
}
function h() external payable {}
function i() external view {
this.h.value(42)();
}
}
// ----
// TypeError: (90-110): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable.
// TypeError: (192-212): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable.
// TypeError: (283-301): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable.