Merge pull request #11750 from ethereum/immutables-10463

Allow reading of immutables during construction time
This commit is contained in:
chriseth
2021-08-19 14:39:03 +02:00
committed by GitHub
40 changed files with 233 additions and 55 deletions
+13 -1
View File
@@ -76,7 +76,8 @@ Immutable
Variables declared as ``immutable`` are a bit less restricted than those
declared as ``constant``: Immutable variables can be assigned an arbitrary
value in the constructor of the contract or at the point of their declaration.
They cannot be read during construction time and can only be assigned once.
They can be assigned only once and can, from that point on, be read even during
construction time.
The contract creation code generated by the compiler will modify the
contract's runtime code before it is returned by replacing all references
@@ -84,3 +85,14 @@ to immutables by the values assigned to the them. This is important if
you are comparing the
runtime code generated by the compiler with the one actually stored in the
blockchain.
.. note::
Immutables that are assigned at their declaration are only considered
initialized once the constructor of the contract is executing.
This means you cannot initialize immutables inline with a value
that depends on another immutable. You can do this, however,
inside the constructor of the contract.
This is a safeguard against different interpretations about the order
of state variable initialization and constructor execution, especially
with regards to inheritance.