hdl.ast: allow typed int enums in Value.cast.

This commit is contained in:
Arusekk 2023-01-22 22:37:49 +01:00 committed by Catherine
parent 91d4513682
commit 58a0c68279
3 changed files with 31 additions and 4 deletions

View file

@ -168,12 +168,12 @@ class Value(metaclass=ABCMeta):
while True:
if isinstance(obj, Value):
return obj
elif isinstance(obj, int):
return Const(obj)
elif isinstance(obj, Enum):
return Const(obj.value, Shape.cast(type(obj)))
elif isinstance(obj, ValueCastable):
new_obj = obj.as_value()
elif isinstance(obj, Enum):
return Const(obj.value, Shape.cast(type(obj)))
elif isinstance(obj, int):
return Const(obj)
else:
raise TypeError("Object {!r} cannot be converted to an Amaranth value".format(obj))
if new_obj is obj: