From bf8faea51e92364564562cd02bf6e9743289e679 Mon Sep 17 00:00:00 2001 From: Wanda Date: Sat, 13 Jan 2024 13:39:02 +0100 Subject: [PATCH] hdl.ast: raise a sensible error for `xxx in Value` --- amaranth/hdl/ast.py | 3 +++ tests/test_hdl_ast.py | 5 +++++ 2 files changed, 8 insertions(+) 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):