hdl.ast: ensure Value.cast in Part and Slice constructors.

This commit is contained in:
Marcelina Kościelnicka 2023-06-07 17:34:28 +02:00 committed by Catherine
parent 1b0fb1afbc
commit 51391be1ae

View file

@ -798,6 +798,7 @@ class Slice(Value):
if not isinstance(stop, int):
raise TypeError("Slice stop must be an integer, not {!r}".format(stop))
value = Value.cast(value)
n = len(value)
if start not in range(-n, n+1):
raise IndexError("Cannot start slice {} bits into {}-bit value".format(start, n))
@ -811,7 +812,7 @@ class Slice(Value):
raise IndexError("Slice start {} must be less than slice stop {}".format(start, stop))
super().__init__(src_loc_at=src_loc_at)
self.value = Value.cast(value)
self.value = value
self.start = int(start)
self.stop = int(stop)
@ -837,7 +838,7 @@ class Part(Value):
raise TypeError("Part stride must be a positive integer, not {!r}".format(stride))
super().__init__(src_loc_at=src_loc_at)
self.value = value
self.value = Value.cast(value)
self.offset = Value.cast(offset)
self.width = width
self.stride = stride