I am using REMIX IDE and on running the below code
// SPDX-License-Identifier:MIT
pragma solidity 0.8.6;
contract enum1{
enum FreshJuice{small,medium,large}
FreshJuice choice;
FreshJuice constant defaultChoice=FreshJuice.medium;
function setLarge() public{
choice=FreshJuice.large;
}
function setSmall() public{
choice=FreshJuice.small;
}
function getChoice() public view returns(FreshJuice){
return choice;
}
function getDefault() public view returns(uint){
return uint(defaultChoice);
}
}
I am getting this warning
Warning: Function state mutability can be restricted to pure
--> contracts/enumerator.sol:23:5:
|
23 | function getDefault() public view returns(uint){
| ^ (Relevant source part starts here and spans across multiple lines).
But after changing view to pure in line 23, it doesn't give warning.
// SPDX-License-Identifier:MIT
pragma solidity 0.8.6;
contract enum1{
enum FreshJuice{small,medium,large}
FreshJuice choice;
FreshJuice constant defaultChoice=FreshJuice.medium;
function setLarge() public{
choice=FreshJuice.large;
}
function setSmall() public{
choice=FreshJuice.small;
}
function getChoice() public view returns(FreshJuice){
return choice;
}
function getDefault() public pure returns(uint){
return uint(defaultChoice);
}
}
Also how a pure function can read state variable.