mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Allow reading of immutables during construction time
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
contract C {
|
||||
uint immutable public a;
|
||||
uint immutable public b;
|
||||
uint immutable public c;
|
||||
uint immutable public d;
|
||||
|
||||
constructor() {
|
||||
a = 1;
|
||||
b = a;
|
||||
c = b;
|
||||
d = c;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// a() -> 1
|
||||
// b() -> 1
|
||||
// c() -> 1
|
||||
// d() -> 1
|
||||
@@ -0,0 +1,22 @@
|
||||
contract A {
|
||||
uint8 immutable a;
|
||||
uint8 x;
|
||||
|
||||
constructor() {
|
||||
a = 3;
|
||||
x = readA();
|
||||
}
|
||||
|
||||
function readX() public view returns (uint8) {
|
||||
return x;
|
||||
}
|
||||
|
||||
function readA() public view returns (uint8) {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// readX() -> 3
|
||||
// readA() -> 3
|
||||
@@ -0,0 +1,17 @@
|
||||
contract A {
|
||||
uint8 immutable a;
|
||||
uint8 x;
|
||||
|
||||
constructor() {
|
||||
a = 3;
|
||||
x = a;
|
||||
}
|
||||
|
||||
function readX() public view returns (uint8) {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// readX() -> 3
|
||||
Reference in New Issue
Block a user