solidity/test/libsolidity/semanticTests/immutable/multi_creation.sol
2021-03-29 11:02:31 +02:00

37 lines
634 B
Solidity

contract A {
uint immutable a;
constructor() {
a = 7;
}
function f() public view returns (uint) { return a; }
}
contract B {
uint immutable a;
constructor() {
a = 5;
}
function f() public view returns (uint) { return a; }
}
contract C {
uint immutable a;
uint public x;
uint public y;
constructor() {
a = 3;
x = (new A()).f();
y = (new B()).f();
}
function f() public returns (uint256, uint, uint) {
return (a, (new A()).f(), (new B()).f());
}
}
// ====
// compileViaYul: also
// ----
// f() -> 3, 7, 5
// gas irOptimized: 133434
// gas legacy: 153990
// gas legacyOptimized: 127822
// x() -> 7
// y() -> 5