Relax restrictions on immutable initialization

This commit is contained in:
Kamil Śliwak
2023-07-14 15:29:32 +02:00
parent 490b90d0ab
commit dad2bf6472
54 changed files with 178 additions and 396 deletions
@@ -0,0 +1,15 @@
contract C {
uint8 immutable public a;
uint8 immutable public b = 0x42;
uint public c;
constructor() {
delete a;
delete b;
c = b * 2 + a;
}
}
// ----
// a() -> 0
// b() -> 0
// c() -> 0
@@ -0,0 +1,18 @@
contract C {
int immutable x = 1;
int immutable y = 3;
constructor() {
x--;
--x;
y++;
++y;
--y;
}
function f() public view returns (int, int) {
return (x, y);
}
}
// ----
// f() -> -1, 4
@@ -0,0 +1,27 @@
contract A {
uint immutable x = x + 1;
uint immutable y = x += 2;
constructor(uint) m(x += 16) m(x += 32) {
x += 64;
x += 128;
}
modifier m(uint) {
_;
}
function get() public returns (uint) {
return x;
}
}
contract B is A(A.x += 8) {
constructor(uint) {}
}
contract C is B {
constructor() B(x += 4) {}
}
// ----
// get() -> 0xff
@@ -0,0 +1,11 @@
contract C {
uint immutable u;
bool immutable b;
address immutable a;
function get() public returns (uint, bool, address) {
return (u, b, a);
}
}
// ----
// get() -> 0, false, 0x0