Merge pull request #6938 from ethereum/gasValueMutability

Set state mutability of function type members ``gas`` and ``value`` to pure.
This commit is contained in:
Daniel Kirchner 2019-06-13 19:33:27 +02:00 committed by GitHub
commit 7187a3e5ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 2 deletions

View File

@ -10,6 +10,7 @@ Compiler Features:
Bugfixes:
* Yul / Inline Assembly Parser: Disallow trailing commas in function call arguments.
* Set state mutability of the function type members ``gas`` and ``value`` to pure (while their return type inherits state mutability from the function type).
Build System:

View File

@ -2912,7 +2912,7 @@ MemberList::MemberMap FunctionType::nativeMembers(ContractDefinition const*) con
strings(1, ""),
Kind::SetValue,
false,
StateMutability::NonPayable,
StateMutability::Pure,
nullptr,
m_gasSet,
m_valueSet
@ -2929,7 +2929,7 @@ MemberList::MemberMap FunctionType::nativeMembers(ContractDefinition const*) con
strings(1, ""),
Kind::SetGas,
false,
StateMutability::NonPayable,
StateMutability::Pure,
nullptr,
m_gasSet,
m_valueSet

View File

@ -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);
}
}

View File

@ -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.

View File

@ -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
// ----

View File

@ -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.