Skip to content

Immutable variables treated differently depending on type #15989

Open
@frangio

Description

@frangio

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

// 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
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛medium effortDefault level of effortmedium impactDefault level of impactmust have eventuallySomething we consider essential but not enough to prevent us from releasing Solidity 1.0 without it.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions