diff --git a/amaranth/hdl/ast.py b/amaranth/hdl/ast.py index 26be377..7f7dfc7 100644 --- a/amaranth/hdl/ast.py +++ b/amaranth/hdl/ast.py @@ -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. diff --git a/tests/test_hdl_ast.py b/tests/test_hdl_ast.py index 4e52c6b..81ba518 100644 --- a/tests/test_hdl_ast.py +++ b/tests/test_hdl_ast.py @@ -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):