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, 2021 at 6:29
  • I guess you cannot change the interface, right? Apr 7, 2021 at 7:13
  • The interface has to be view ... this implementation has no need to read the state, but other implementations do. Apr 7, 2021 at 15:02
  • hi, have You found a better way to do it :) ?
    – Majd TL
    Oct 29, 2021 at 11:19
  • Not yet, and I've moved on. Would be interested in a way to silence it. Nov 1, 2021 at 20:30


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.