From 51391be1ae2fdb115ad44f80de871a2150cb9eeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcelina=20Ko=C5=9Bcielnicka?= Date: Wed, 7 Jun 2023 17:34:28 +0200 Subject: [PATCH] hdl.ast: ensure `Value.cast` in `Part` and `Slice` constructors. --- amaranth/hdl/ast.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/amaranth/hdl/ast.py b/amaranth/hdl/ast.py index 669af17..0b4939d 100644 --- a/amaranth/hdl/ast.py +++ b/amaranth/hdl/ast.py @@ -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