From c41a5209634f10c096bfd9aaa9179ae79233b7f7 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 18 Mar 2021 23:52:23 +0000 Subject: [PATCH] hdl.ast: handle int subclasses as slice start/stop values. Fixes #601. --- nmigen/hdl/ast.py | 4 ++-- tests/test_hdl_ast.py | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/nmigen/hdl/ast.py b/nmigen/hdl/ast.py index b410844..0356e7d 100644 --- a/nmigen/hdl/ast.py +++ b/nmigen/hdl/ast.py @@ -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) diff --git a/tests/test_hdl_ast.py b/tests/test_hdl_ast.py index af073a9..78c956d 100644 --- a/tests/test_hdl_ast.py +++ b/tests/test_hdl_ast.py @@ -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'$"): -- 2.30.2