hdl.ast: raise a sensible error for xxx in Value

This commit is contained in:
Wanda 2024-01-13 13:39:02 +01:00 committed by Catherine
parent 86d14f584e
commit bf8faea51e
2 changed files with 8 additions and 0 deletions

View file

@ -377,6 +377,9 @@ class Value(metaclass=ABCMeta):
else:
raise TypeError(f"Cannot index value with {key!r}")
def __contains__(self, other):
raise TypeError("Cannot use 'in' with an Amaranth value")
def as_unsigned(self):
"""Conversion to unsigned.

View file

@ -750,6 +750,11 @@ class OperatorTestCase(FHDLTestCase):
""")
self.assertEqual(abs(s).shape(), unsigned(4))
def test_contains(self):
with self.assertRaisesRegex(TypeError,
r"^Cannot use 'in' with an Amaranth value$"):
1 in Signal(3)
class SliceTestCase(FHDLTestCase):
def test_shape(self):