#16419·solidity

`isConstant` annotation in the AST is always false

Author: cameelCreated Jan 26, 2026Updated Sep 24, 2026
Labelsbug :bug:low effortlow impactmust have eventually

Description

isConstant in the AST is supposed to be true when the node is an identifier (or member access) that refers to a constant variable. This appears to be true internally, but in the exported AST the annotation is false instead.

Environment

Reproducible on 0.8.33, develop and as far back as 0.5.0.

Steps to Reproduce

solidity
uint constant X = 1234;

contract C {
    uint constant Y = 5678;

    function f() public returns (uint) {
        return X + Y;
    }
}
solc test.sol --ast-compact-json --pretty-json --json-indent 4 | grep isConstant
                "isConstant": false,
                        "isConstant": false,
                                    "isConstant": false,

The bug is likely to be in the JSON exporter. I checked the place where we assign the value during analysis by placing an assertion there and the value is true but only false is present in the JSON output: https://github.com/argotorg/solidity/blob/64118f21280f0196f491689f0fc93dc5bec20dc1/libsolidity/analysis/TypeChecker.cpp#L3698