mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #6938 from ethereum/gasValueMutability
Set state mutability of function type members ``gas`` and ``value`` to pure.
This commit is contained in:
commit
7187a3e5ca
@ -10,6 +10,7 @@ Compiler Features:
|
|||||||
|
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
* Yul / Inline Assembly Parser: Disallow trailing commas in function call arguments.
|
* 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:
|
Build System:
|
||||||
|
@ -2912,7 +2912,7 @@ MemberList::MemberMap FunctionType::nativeMembers(ContractDefinition const*) con
|
|||||||
strings(1, ""),
|
strings(1, ""),
|
||||||
Kind::SetValue,
|
Kind::SetValue,
|
||||||
false,
|
false,
|
||||||
StateMutability::NonPayable,
|
StateMutability::Pure,
|
||||||
nullptr,
|
nullptr,
|
||||||
m_gasSet,
|
m_gasSet,
|
||||||
m_valueSet
|
m_valueSet
|
||||||
@ -2929,7 +2929,7 @@ MemberList::MemberMap FunctionType::nativeMembers(ContractDefinition const*) con
|
|||||||
strings(1, ""),
|
strings(1, ""),
|
||||||
Kind::SetGas,
|
Kind::SetGas,
|
||||||
false,
|
false,
|
||||||
StateMutability::NonPayable,
|
StateMutability::Pure,
|
||||||
nullptr,
|
nullptr,
|
||||||
m_gasSet,
|
m_gasSet,
|
||||||
m_valueSet
|
m_valueSet
|
||||||
|
@ -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.
|
Loading…
Reference in New Issue
Block a user