Skip to content

Commit bf8faea

Browse files
wanda-phiwhitequark
authored andcommitted
hdl.ast: raise a sensible error for xxx in Value
1 parent 86d14f5 commit bf8faea

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

amaranth/hdl/ast.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,9 @@ def __getitem__(self, key):
377377
else:
378378
raise TypeError(f"Cannot index value with {key!r}")
379379

380+
def __contains__(self, other):
381+
raise TypeError("Cannot use 'in' with an Amaranth value")
382+
380383
def as_unsigned(self):
381384
"""Conversion to unsigned.
382385

tests/test_hdl_ast.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,11 @@ def test_abs(self):
750750
""")
751751
self.assertEqual(abs(s).shape(), unsigned(4))
752752

753+
def test_contains(self):
754+
with self.assertRaisesRegex(TypeError,
755+
r"^Cannot use 'in' with an Amaranth value$"):
756+
1 in Signal(3)
757+
753758

754759
class SliceTestCase(FHDLTestCase):
755760
def test_shape(self):

0 commit comments

Comments
 (0)