Suppose I have an interface:

pragma solidity 0.7.6;

interface Foo {
  function foo() public view returns(bool);

And a simplistic implementation like a mock:

contract Bar is Foo {

  function foo() public view returns(bool} {
    this; // silence state mutability warning
    return true;

This part:


... sort of works. See here: Function overriding versus Solidity Compiler Warning: Function state mutability can be restricted to pure

It seems clean enough with truffle compile and hardhat compile but solidity-coverage still complains about it:

state mutability can be restricted to pure

Sure, but this is a false positive. We don't want to change any code. The perfectionist in me doesn't want to see alarming warnings where no issue exists.

Is there a better way to silence the warning?

Thanks :-)

  • I'm not sure I understand. The warning is a valid warning - why not use pure. Apr 7 at 6:29
  • I guess you cannot change the interface, right? Apr 7 at 7:13
  • The interface has to be view ... this implementation has no need to read the state, but other implementations do. Apr 7 at 15:02

Your Answer

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

Browse other questions tagged or ask your own question.