0

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"

enter image description here

0

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.

| improve this answer | |
0

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.