I have a function in a base contract that could have the state mutability modifier "pure" because it always returns true:
BaseContract {
function x(bytes memory)
public
view
returns(bool)
{
return true
}
}
However, this function is usually overridden in derived contracts, like so:
DerivedContract is Base {
function x (bytes memory payload)
public
view
returns(bool)
{
// do some non-pure stuff
// return true OR false
}
}
My question regarding how to silence this compiler warning is rooted in deeper questions:
- Does function overriding in Solidity still work, even if the to-be-overidden function has a non-identical state mutability modifier?
- Therefore, can I change the state-mutability modifier of the base function to pure, and still have this function overridden, or will the two dissimilar state mutabilities (view vs. pure), all else being identical, result in some sort of function overloading?
- If overriding a function with a dissimilar state mutability does not work, how can I silence the aforementioned compiler warning?
Thanks for your help!
gettersandinternalvsexternalfunctions, would be to write aninterface, from which toinherit, just for this one function. This seems a little dirty. What do you think? Also, can you explain why thestate mutability warningis bypassed, if youinheritthe function from aninterface, please? – Luis Schliesske Oct 06 '19 at 08:38contracttointerfaceand/or when changing the function frompublictoexternal. Perhaps the compiler implementation is such that acontractdictates tight restrictions (e.g., function should beview) and aninterfacedictates weaker restrictions (e.g., function can beviewor "lower"). Perhaps this is even dictated by the Solidity language standard, in which case, you could find it in the official documentation. – goodvibration Oct 06 '19 at 09:11enumdeclaration is not yet supported (at least in Solc v0.4.x). That one definitely is a downside. – goodvibration Oct 06 '19 at 09:18function _msgData() internal view returns (bytes memory) { // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 this; return msg.data; }
– Luis Schliesske Oct 09 '19 at 16:32