hdl.ast: clarify exception message for out of bounds indexing.
Fixes #488.
This commit is contained in:
parent
5b01499901
commit
fde242aa47
|
@ -254,7 +254,7 @@ class Value(metaclass=ABCMeta):
|
||||||
n = len(self)
|
n = len(self)
|
||||||
if isinstance(key, int):
|
if isinstance(key, int):
|
||||||
if key not in range(-n, n):
|
if key not in range(-n, n):
|
||||||
raise IndexError("Cannot index {} bits into {}-bit value".format(key, n))
|
raise IndexError(f"Index {key} is out of bounds for a {n}-bit value")
|
||||||
if key < 0:
|
if key < 0:
|
||||||
key += n
|
key += n
|
||||||
return Slice(self, key, key + 1)
|
return Slice(self, key, key + 1)
|
||||||
|
|
|
@ -187,7 +187,7 @@ class ValueTestCase(FHDLTestCase):
|
||||||
self.assertEqual(s2.start, 3)
|
self.assertEqual(s2.start, 3)
|
||||||
self.assertEqual(s2.stop, 4)
|
self.assertEqual(s2.stop, 4)
|
||||||
with self.assertRaisesRegex(IndexError,
|
with self.assertRaisesRegex(IndexError,
|
||||||
r"^Cannot index 5 bits into 4-bit value$"):
|
r"^Index 5 is out of bounds for a 4-bit value$"):
|
||||||
Const(10)[5]
|
Const(10)[5]
|
||||||
|
|
||||||
def test_getitem_slice(self):
|
def test_getitem_slice(self):
|
||||||
|
|
Loading…
Reference in a new issue