Skip to content

Enum max values can't be used to dimension an array #12886

@gpersoon

Description

@gpersoon

Description

Enum max values can't be used to dimension an array.
An enum max value can be assigned to a constant. But that constant can't be used as an array size.
'Normal' constants can be used to dimension an array.
See example below.

Environment

  • Compiler version: 0.8.13
  • Target EVM version (as per compiler settings): default
  • Framework/IDE (e.g. Truffle or Remix): Remix
  • EVM execution environment / backend / blockchain client:
  • Operating system: Windows

Steps to Reproduce

//SPDX-License-Identifier: MIT
pragma solidity 0.8.13;

contract test {
    enum ParameterIndexes { P1,P2 }
    uint constant x1 = uint(type(ParameterIndexes).max);
    uint256[x1] params1; // Doesn't compile: Error expected integer literal or constant expression

    uint256[uint(type(ParameterIndexes).max)] params2; // Doesn't compile: Error expected integer literal or constant expression

    uint constant x2 = 7;
    uint256[x2] params3; // Does compile
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    closed due inactivityThe issue/PR was automatically closed due to inactivity.language design :rage4:Any changes to the language, e.g. new featuresstaleThe issue/PR was marked as stale because it has been open for too long.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions