You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/ir-breaking-changes.rst
+42-41Lines changed: 42 additions & 41 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,6 +30,48 @@ Semantic Only Changes
30
30
This section lists the changes that are semantic-only, thus potentially
31
31
hiding new and different behavior in existing code.
32
32
33
+
- The order of state variable initialization has changed in case of inheritance.
34
+
35
+
The order used to be:
36
+
37
+
- All state variables are zero-initialized at the beginning.
38
+
- Evaluate base constructor arguments from most derived to most base contract.
39
+
- Initialize all state variables in the whole inheritance hierarchy from most base to most derived.
40
+
- Run the constructor, if present, for all contracts in the linearized hierarchy from most base to most derived.
41
+
42
+
New order:
43
+
44
+
- All state variables are zero-initialized at the beginning.
45
+
- Evaluate base constructor arguments from most derived to most base contract.
46
+
- For every contract in order from most base to most derived in the linearized hierarchy:
47
+
48
+
1. Initialize state variables.
49
+
2. Run the constructor (if present).
50
+
51
+
This causes differences in contracts where the initial value of a state
52
+
variable relies on the result of the constructor in another contract:
53
+
54
+
.. code-block:: solidity
55
+
56
+
// SPDX-License-Identifier: GPL-3.0
57
+
pragma solidity >=0.7.1;
58
+
59
+
contract A {
60
+
uint x;
61
+
constructor() {
62
+
x = 42;
63
+
}
64
+
function f() public view returns(uint256) {
65
+
return x;
66
+
}
67
+
}
68
+
contract B is A {
69
+
uint public y = f();
70
+
}
71
+
72
+
Previously, ``y`` would be set to 0. This is due to the fact that we would first initialize state variables: First, ``x`` is set to 0, and when initializing ``y``, ``f()`` would return 0 causing ``y`` to be 0 as well.
73
+
With the new rules, ``y`` will be set to 42. We first initialize ``x`` to 0, then call A's constructor which sets ``x`` to 42. Finally, when initializing ``y``, ``f()`` returns 42 causing ``y`` to be 42.
74
+
33
75
- When storage structs are deleted, every storage slot that contains
34
76
a member of the struct is set to zero entirely. Formerly, padding space
35
77
was left untouched.
@@ -112,47 +154,6 @@ hiding new and different behavior in existing code.
112
154
- New code generator: ``0`` as all parameters, including return parameters, will be re-initialized before
113
155
each ``_;`` evaluation.
114
156
115
-
- The order of contract initialization has changed in case of inheritance.
116
-
117
-
The order used to be:
118
-
119
-
- All state variables are zero-initialized at the beginning.
120
-
- Evaluate base constructor arguments from most derived to most base contract.
121
-
- Initialize all state variables in the whole inheritance hierarchy from most base to most derived.
122
-
- Run the constructor, if present, for all contracts in the linearized hierarchy from most base to most derived.
123
-
124
-
New order:
125
-
126
-
- All state variables are zero-initialized at the beginning.
127
-
- Evaluate base constructor arguments from most derived to most base contract.
128
-
- For every contract in order from most base to most derived in the linearized hierarchy execute:
129
-
130
-
1. If present at declaration, initial values are assigned to state variables.
131
-
2. Constructor, if present.
132
-
133
-
This causes differences in some contracts, for example:
134
-
135
-
.. code-block:: solidity
136
-
137
-
// SPDX-License-Identifier: GPL-3.0
138
-
pragma solidity >=0.7.1;
139
-
140
-
contract A {
141
-
uint x;
142
-
constructor() {
143
-
x = 42;
144
-
}
145
-
function f() public view returns(uint256) {
146
-
return x;
147
-
}
148
-
}
149
-
contract B is A {
150
-
uint public y = f();
151
-
}
152
-
153
-
Previously, ``y`` would be set to 0. This is due to the fact that we would first initialize state variables: First, ``x`` is set to 0, and when initializing ``y``, ``f()`` would return 0 causing ``y`` to be 0 as well.
154
-
With the new rules, ``y`` will be set to 42. We first initialize ``x`` to 0, then call A's constructor which sets ``x`` to 42. Finally, when initializing ``y``, ``f()`` returns 42 causing ``y`` to be 42.
155
-
156
157
- Copying ``bytes`` arrays from memory to storage is implemented in a different way.
157
158
The old code generator always copies full words, while the new one cuts the byte
158
159
array after its end. The old behaviour can lead to dirty data being copied after
0 commit comments