mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Relax restrictions on immutable initialization
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user