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.
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.
Activity