Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

View getter functions referencing immutable value types cannot be defined as pure #15096

Open
Ashraile opened this issue May 12, 2024 · 1 comment

Comments

@Ashraile
Copy link

Description

Immutable variables replace their values at deployment with compile-time constants (as inlined bytecode). This necessarily means that any getter functions for immutable value types do not view contract state and so can be defined as pure instead of view, however the compiler does not allow this.

Environment

  • Compiler version: 0.8.25 (and below)
  • Target EVM version (as per compiler settings): cancun (and others)
  • Framework/IDE (e.g. Truffle or Remix): Remix
  • EVM execution environment / backend / blockchain client: Remix
  • Operating system: Windows 10

Steps to Reproduce

contract ImmutableGetter {
    uint256 private immutable _releaseDate;
    constructor() {
        _releaseDate = block.timestamp;
    }
    // pure throws with ("potentially reads from environment or state"). This is lazy
    function releaseDate() public view /* pure */ returns (uint256) {
        return _releaseDate;
    }
}
@nikola-matic
Copy link
Collaborator

Heya @Ashraile and thanks for the issue. Now, just to be clear, we don't consider this to be a bug per-se, but the topic itself has been quite contentious and we still don't have a definitive decision on what to about the pure decorator. Some people are for the opposite of what you suggest - i.e. strengthening pure even further, but some are again the opposite of that. You can see some of the discussion in #8153. There's some further reading in the following issues as well: #12829, #9554. The reason we don't consider it a bug is because it's technically reading a state variable (which of course most would assume to mean reading from storage). I'll triage this and keep it open, since it's definitely something that could be improved upon, but as you can see from the multitude of similar issues, it's not easy to come to an agreement, so it will take some time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants