argotorg / argotorg/solidity

Compile-time evaluation of member constants

Open
#16,055 1 comment 0 reactions 1 assignee Claimed by @matheusaaguiar View on GitHub
low effort low impact must have eventually
Dominant language
C++
Stars
25.7k
Forks
6.2k
Avg merge
2d 19h
Merged PRs (30d)
29

Description

## Abstract

In contexts where a compile-time constant expression is expected, we currently allow constants initialized with literal expressions, but only when the constant is referenced via a standalone identifier (e.g. `X`). It does not work when it's via a member access expression (e.g. `C.X`). Both should work.

```solidity
contract D {
uint constant LENGTH = 42;
uint[LENGTH] x; // OK
uint[D.LENGTH] y; // Error: Invalid array length, expected integer literal or constant expression.
}
```

## Motivation
This limitation is unintuitive and the error message does not make it clear what the problem is.

The problem is also likely to become more common once we allow using constants in layout specifiers (#15944).

## Specification
In contexts where we use `ConstantEvaluator` to evaluate expressions at compilation time (array sizes or layout specifiers, etc), it should be possible to reference constants even if they are accessed via member access on contracts, modules or any other objects.

It should also be possible to use member access expressions inside constant initializers (e.g. `uint constant X = m.Y`).

## Backwards Compatibility

Full compatibility. It will affect only situations that currently produce an error.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.