Mark chainid as view.

This commit is contained in:
Daniel Kirchner 2020-12-09 16:00:02 +01:00
parent fca8026250
commit 588535566f
6 changed files with 15 additions and 2 deletions

View File

@ -22,6 +22,7 @@ Breaking Changes:
* Type System: Explicit conversions from literals to enums are only allowed if the value fits in the enum.
* Type System: Explicit conversions from literals to integer type is as strict as implicit conversions.
* Type System: Unary negation can only be used on signed integers, not on unsigned integers.
* View Pure Checker: Mark ``chainid`` as view.
Language Features:
* Super constructors can now be called using the member notation e.g. ``M.C(123)``.

View File

@ -91,6 +91,8 @@ New Restrictions
* Remove support for the ``\b``, ``\f``, and ``\v`` escape sequences in code.
They can still be inserted via hexadecimal escapes, e.g. ``\x08``, ``\x0c``, and ``\x0b``, respectively.
* The ``chainid`` builtin in inline assembly is now considered ``view`` instead of ``pure``.
Interface Changes
=================

View File

@ -365,6 +365,7 @@ bool SemanticInformation::invalidInPureFunctions(Instruction _instruction)
case Instruction::ORIGIN:
case Instruction::CALLER:
case Instruction::CALLVALUE:
case Instruction::CHAINID:
case Instruction::GAS:
case Instruction::GASPRICE:
case Instruction::EXTCODESIZE:

View File

@ -1,5 +1,5 @@
contract C {
function f() pure external returns (uint id) {
function f() view external returns (uint id) {
assembly {
id := chainid()
}

View File

@ -0,0 +1,9 @@
contract C {
function f() public pure {
assembly { pop(chainid()) }
}
}
// ====
// EVMVersion: >=istanbul
// ----
// TypeError 2527: (67-76): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".

View File

@ -1,5 +1,5 @@
contract C {
function f() public pure {
function f() public view {
assembly { pop(chainid()) }
}
}