hdl.ast: handle int subclasses as slice start/stop values.
authorwhitequark <whitequark@whitequark.org>
Thu, 18 Mar 2021 23:52:23 +0000 (23:52 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 31 Dec 2021 15:26:46 +0000 (15:26 +0000)
Fixes #601.

nmigen/hdl/ast.py
tests/test_hdl_ast.py

index b410844f816ebb57232e89f8dbc5fd484a9256a8..0356e7d52b5c0d8bfb07ccd6c414bbdc0caa031f 100644 (file)
@@ -765,8 +765,8 @@ class Slice(Value):
 
         super().__init__(src_loc_at=src_loc_at)
         self.value = Value.cast(value)
-        self.start = start
-        self.stop  = stop
+        self.start = int(start)
+        self.stop  = int(stop)
 
     def shape(self):
         return Shape(self.stop - self.start)
index af073a984fdc97fd55b88ccb7adac9226fde113e..78c956d650dfec2222d84abbadae4a4d2161419d 100644 (file)
@@ -630,6 +630,12 @@ class SliceTestCase(FHDLTestCase):
         s1 = Slice(c, -4, -1)
         self.assertEqual((s1.start, s1.stop), (4, 7))
 
+    def test_start_end_bool(self):
+        c  = Const(0, 8)
+        s  = Slice(c, False, True)
+        self.assertIs(type(s.start), int)
+        self.assertIs(type(s.stop),  int)
+
     def test_start_end_wrong(self):
         with self.assertRaisesRegex(TypeError,
                 r"^Slice start must be an integer, not 'x'$"):