argotorg / argotorg/solidity

Immutable variables treated differently depending on type

Open
#15,989 9 comments 3 reactions 0 assignees View on GitHub
bug :bug: medium effort medium impact must have eventually
Dominant language
C++
Stars
25.7k
Forks
6.2k
Avg merge
2d 19h
Merged PRs (30d)
29

Description

## Description

An immutable variable that is initialized at declaration site can be used in `pure` context if it is of type `uint` but not if it is of type `address`.

## Environment

- Compiler version: 0.8.29

## Steps to Reproduce

```solidity
// SPDX-License-Identifier: GPL-3.0

pragma solidity 0.8.29;

contract Test {
address internal immutable _a = 0x0000000000000000000000000000000000000001;
uint256 internal immutable _b = 42;

function a() external pure returns (address) {
return _a; // TypeError: Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
}

function b() external pure returns (uint256) {
return _b; // no error
}
}
```

Contributor guide

Open the contributing guide

Research direction

Start by compiling the provided Solidity reproducer with compiler version 0.8.29 and compare the pure-context handling of the immutable uint and address variables. Trace the compiler path that classifies immutable reads, then add regression coverage showing consistent behavior for both types; done means the intended pure functions compile without an incorrect diagnostic.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, solidity
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.