Skip to content

Unshaped enumeration values don't work when used in a constant initializer #1413

Closed
@whitequark

Description

@whitequark

To reproduce:

from amaranth.lib import enum, data

class QSPIMode(enum.Enum):
    PutX1 = 0

data.StructLayout({"mode": QSPIMode}).const({"mode": QSPIMode.PutX1})
  File ".../bug.py", line 6, in <module>
    data.StructLayout({"mode": QSPIMode}).const({"mode": QSPIMode.PutX1})
  File ".../python3.12/site-packages/amaranth/lib/data.py", line 232, in const
    key_value = hdl.Const(key_value, cast_field_shape)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../python3.12/site-packages/amaranth/hdl/_ast.py", line 1551, in __call__
    return super().__call__(value, shape, **kwargs, src_loc_at=src_loc_at + 1)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../python3.12/site-packages/amaranth/hdl/_ast.py", line 1601, in __init__
    value = int(operator.index(value))
                ^^^^^^^^^^^^^^^^^^^^^
TypeError: 'QSPIMode' object cannot be interpreted as an integer

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions