I am getting the warning on the code shown below. Could you please assist me know to resolve this warning ?
warning message - "Is constant but potentially should not be"
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communityI am getting the warning on the code shown below. Could you please assist me know to resolve this warning ?
warning message - "Is constant but potentially should not be"
Same issue is discussed here but did not reach any conclusion.
I think this is happening because of new
keyword while creating variable string abcde
.
I have tried two example contracts for the confirmation.
pragma solidity ^0.4.24;
contract Foo {
uint256 n = 10;
function initArray() public view {
uint[10*10] memory result;
for (uint i = 0; i < n; i++){
for(uint j = 0; j < n; j++){
result[(i*9)+j]=1;
}
}
}
}
For the above smart contract, remix doesn't throw a warning Is constant but potentially should not be
.
pragma solidity ^0.4.24;
contract Foo {
uint256 n = 10;
function initArray() public view {
uint[] memory result = new uint[](n*n);
for (uint i = 0; i < n; i++){
for(uint j = 0; j < n; j++){
result[(i*9)+j]=1;
}
}
}
}
However, for the above contract remix throws the warning: Is constant but potentially should not be.
The function writes to a state variable babcde[]
defined elsewhere. Since it writes to the state, the read-only pure
modifier is probably in error.
Hope it helps.