Allow reading of immutables during construction time

This commit is contained in:
Marenz
2021-08-19 13:59:05 +02:00
committed by chriseth
parent 729db521a9
commit 121fd40f74
40 changed files with 233 additions and 55 deletions
@@ -7,4 +7,4 @@ contract C {
function f() public pure returns (uint) { return 3 + x; }
}
// ----
// TypeError 7733: (136-137): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
// TypeError 7733: (136-137): Immutable variables cannot be read before they are initialized.
@@ -5,4 +5,4 @@ contract C {
}
}
// ----
// TypeError 7733: (71-72): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
// TypeError 7733: (71-72): Immutable variables cannot be read before they are initialized.
@@ -11,4 +11,4 @@ contract C {
function f(uint a) internal pure {}
}
// ----
// TypeError 7733: (119-120): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
// TypeError 7733: (119-120): Immutable variables cannot be read before they are initialized.
@@ -5,4 +5,4 @@ contract C {
}
}
// ----
// TypeError 7733: (63-64): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
// TypeError 3969: (63-64): Immutable variables must be initialized using an assignment.
@@ -5,4 +5,4 @@ contract C {
}
}
// ----
// TypeError 7733: (70-71): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
// TypeError 3969: (70-71): Immutable variables must be initialized using an assignment.
@@ -5,5 +5,4 @@ contract C {
}
}
// ----
// TypeError 1574: (74-75): Immutable state variable already initialized.
// TypeError 7733: (74-75): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
// TypeError 2718: (74-75): Immutable variables cannot be modified after initialization.
@@ -4,4 +4,4 @@ contract C {
function f() public pure returns (uint) { return 3 + x; }
}
// ----
// TypeError 7733: (99-100): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
// TypeError 7733: (99-100): Immutable variables cannot be read before they are initialized.
@@ -11,3 +11,4 @@ contract C is B(C.f) {
}
// ----
// TypeError 1581: (200-201): Cannot write to immutable here: Immutable variables can only be initialized inline or assigned directly in the constructor.
// TypeError 1574: (109-110): Immutable state variable already initialized.
@@ -10,4 +10,4 @@ contract C is B(C.f) {
function f() internal returns(uint) { return x + 2; }
}
// ----
// TypeError 7733: (200-201): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
// TypeError 7733: (200-201): Immutable variables cannot be read before they are initialized.
@@ -5,4 +5,4 @@ contract C {
}
}
// ----
// TypeError 7733: (63-64): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
// TypeError 3969: (63-64): Immutable variables must be initialized using an assignment.
@@ -7,5 +7,5 @@ contract C {
}
}
// ----
// TypeError 7733: (77-78): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
// TypeError 7733: (86-87): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
// TypeError 3969: (77-78): Immutable variables must be initialized using an assignment.
// TypeError 3969: (86-87): Immutable variables must be initialized using an assignment.
@@ -5,4 +5,4 @@ contract C {
function f() internal returns(uint) { return x; }
}
// ----
// TypeError 7733: (107-108): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
// TypeError 7733: (107-108): Immutable variables cannot be read before they are initialized.
@@ -13,4 +13,4 @@ contract C is B(C.y) {
}
}
// ----
// TypeError 7733: (104-107): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
// TypeError 7733: (104-107): Immutable variables cannot be read before they are initialized.
@@ -16,4 +16,4 @@ contract C is B {
}
}
// ----
// TypeError 7733: (253-254): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
// TypeError 7733: (253-254): Immutable variables cannot be read before they are initialized.
@@ -11,9 +11,8 @@ contract C is B {
B.readX;
}
function readX() internal override returns(uint) {
function readX() internal pure override returns(uint) {
return 3;
}
}
// ----
// TypeError 7733: (109-110): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
@@ -11,9 +11,8 @@ contract C is B {
super.readX();
}
function readX() internal view override returns(uint) {
function readX() internal pure override returns(uint) {
return 1;
}
}
// ----
// TypeError 7733: (114-115): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
@@ -18,4 +18,4 @@ contract C is B {
}
}
// ----
// TypeError 7733: (245-246): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
// TypeError 7733: (245-246): Immutable variables cannot be read before they are initialized.
@@ -0,0 +1,7 @@
contract C { constructor(uint) {} }
contract D is C {
uint immutable t;
constructor() C(t=2) {}
}
// ----
// TypeError 1581: (92-93): Cannot write to immutable here: Immutable variables can only be initialized inline or assigned directly in the constructor.
@@ -0,0 +1,6 @@
contract C { constructor(uint) {} }
contract D is C(D.t = 2) {
uint immutable t;
}
// ----
// TypeError 1581: (52-55): Cannot write to immutable here: Immutable variables can only be initialized inline or assigned directly in the constructor.
@@ -0,0 +1,7 @@
contract D {
uint immutable t;
modifier m(uint) { _; }
constructor() m(t=2) {}
}
// ----
// TypeError 1581: (77-78): Cannot write to immutable here: Immutable variables can only be initialized inline or assigned directly in the constructor.
@@ -26,4 +26,4 @@ contract C is A, B {
}
}
// ----
// TypeError 7733: (489-490): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
// TypeError 7733: (489-490): Immutable variables cannot be read before they are initialized.
@@ -26,4 +26,4 @@ contract C is A, B {
}
}
// ----
// TypeError 7733: (493-494): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
// TypeError 7733: (493-494): Immutable variables cannot be read before they are initialized.
@@ -17,4 +17,4 @@ contract C is B {
}
// ----
// TypeError 7733: (202-203): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
// TypeError 7733: (202-203): Immutable variables cannot be read before they are initialized.
@@ -0,0 +1,12 @@
abstract contract A {
uint public t;
constructor() { t = f(); }
function f() virtual view internal returns (uint);
}
contract B is A {
uint immutable x = 2;
function f() override view internal returns (uint) { return x; }
}
// ----
// TypeError 7733: (223-224): Immutable variables cannot be read before they are initialized.
@@ -0,0 +1,7 @@
contract C {
uint immutable t = 2;
uint x = f();
function f() internal pure returns (uint) { return t; }
}
// ----
// TypeError 7733: (106-107): Immutable variables cannot be read before they are initialized.
@@ -0,0 +1,16 @@
contract C {
uint immutable x ;
constructor()
{
readX();
x = 3;
readX();
}
function readX() public view returns(uint) {
return x;
}
}
// ----
// TypeError 7733: (145-146): Immutable variables cannot be read before they are initialized.
@@ -3,4 +3,4 @@ contract C {
uint y = x;
}
// ----
// TypeError 7733: (52-53): Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
// TypeError 7733: (52-53): Immutable variables cannot be read before they are initialized.
@@ -4,5 +4,5 @@ contract C {
uint immutable y = 5;
}
// ----
// TypeError 1581: (62-63): Cannot write to immutable here: Immutable variables can only be initialized inline or assigned directly in the constructor.
// TypeError 1581: (66-67): Cannot write to immutable here: Immutable variables can only be initialized inline or assigned directly in the constructor.
// TypeError 1581: (62-63): Cannot write to immutable here: Immutable variables can only be initialized inline or assigned directly in the constructor.