question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

solc 0.4.17 compile errors for pure functions

See original GitHub issue

With the truffle 4 beta 2 release which includes the solc@0.4.17 upgrade instrumented contracts containing functions decorated with view will generate a Warning, while those marked as pure will Error with

TypeError: Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".

This is due to the SC instrumented function containing events (which modify state) being present in the pure function.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:22 (15 by maintainers)

github_iconTop GitHub Comments

4reactions
aalavandhancommented, Aug 29, 2018

I seem to be facing the same issue with 0.5.8.

/project/coverageEnv/contracts/MyContract.sol:237:5: TypeError: Overriding function changes state mutability from "view" to "nonpayable".
    function allowance(address owner, address spender) public  returns (uint256) {emit __FunctionCoverageMyContract('/project/coverageEnv/contracts/MyContract.sol',12);
    ^ (Relevant source part starts here and spans across multiple lines).
openzeppelin-zos/contracts/token/ERC20/ERC20.sol:11:3: Overriden function is here:
  function allowance(address owner, address spender) public view returns (uint256);
  ^-------------------------------------------------------------------------------^

MyContract.sol inherits from openzeppelin-zos/contracts/token/ERC20/ERC20.sol and implments the allowance function with the same signature.

function allowance(address owner, address spender) public view returns (uint256) {
     // IMPL     
 }
3reactions
elenadimitrovacommented, Oct 12, 2017

Thanks @cgewecke Compilation failed for me in the following scenario: Contract inhering from another which lives outside the /contracts folder, e.g. a git submodule library for me specifically it looks like this:

/contracts/Token.sol
/lib/dappsys/erc20.sol

This generates compile error:

/coverageEnv/contracts/Token.sol:25:5: TypeError: Overriding function changes state mutability from "view" to "nonpayable".
    function totalSupply() public returns (uint256) {__FunctionCoverageToken('/contracts/Token.sol',1);
    ^
Spanning multiple lines.
/coverageEnv/lib/dappsys/erc20.sol:23:5: Overriden function is here:
    function totalSupply() public view returns (uint supply);
    ^-------------------------------------------------------^
Read more comments on GitHub >

github_iconTop Results From Across the Web

Solidity Documentation - Read the Docs
Solidity is statically typed, supports inheritance, libraries and complex user-defined types among other features.
Read more >
Truffle compiler stuck at 0.4.17 - Ethereum Stack Exchange
If I keep writing, I keep getting errors due to deprecated error highlighting ( constructor and emit events not working, now is okay...)....
Read more >
Contracts — Solidity 0.8.17 documentation
Functions can be declared pure in which case they promise not to read from or modify the state. In particular, it should be...
Read more >
Declare constant at file level in solidity 0.4.17 - Stack Overflow
pragma solidity ^0.4.17; contract MyContract { uint256 constant ... library Constants { function MY_CONSTANT() public pure returns (uint256) ...
Read more >
Contracts — Solidity 0.5.10 documentation - Read the Docs
When a contract is created, its constructor (a function declared with the ... Before version 0.4.17 the compiler did not enforce that pure...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found