Note - Following is a contract that successfully compiled.
In this contract's constructor, I have clearly assigned multiple times to x
.
Why is this okay? What's happening here?
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
contract IsThisImmutable {
uint public s_a = 0;
uint256 public immutable x;
constructor() {
x = 134;
x += 3;
s_a += x;
x += 3;
}
function exp1(uint256 a) public returns(uint256) {
s_a += a;
s_a += x;
return 34;
}
modifier modifier1 {
_;
s_a += 1023;
return;
}
}