solc 0.8.4
I'm trying to save the value of msg.value
in my constructor. If I assign it to one of the state variables, it gets reverted by the EVM when I try to deploy the contract. However, if I assign that state variable a non-zero value (either before or after setting it to msg.value
), then it works.
State variables:
address payable contract_owner;
uint256 wei_received;
Constructor version 1
The wei_received
state variable is set to 1 before it is set to msg.value
.
Success: The contract deploys and the value of wei_received
is set correctly.
constructor () payable
{
contract_owner = payable (msg.sender);
wei_received = 1;
wei_received = msg.value;
}
Constructor version 2
The wei_received
state variable is not being set to 1.
Failure: Reverted by the EVM at time of deployment.
constructor () payable
{
contract_owner = payable (msg.sender);
wei_received = msg.value;
}
Constructor version 3
The wei_received
state variable is set to 1 after it is set to msg.value
.
Failure: The contract deploys but the value of wei_received
is set incorrectly.
constructor () payable
{
contract_owner = payable (msg.sender);
wei_received = msg.value;
wei_received = 1;
}
Is that by design for some reason? Is it a bug in this version of solidity? The workaround is simple, but I'm wondering if anyone else has noticed this and if there is a reason for it.