diff --git a/amaranth/hdl/ast.py b/amaranth/hdl/ast.py index 6a6cbee..a97b90f 100644 --- a/amaranth/hdl/ast.py +++ b/amaranth/hdl/ast.py @@ -166,6 +166,9 @@ class Value(metaclass=ABCMeta): def __bool__(self): raise TypeError("Attempted to convert Amaranth value to Python boolean") + def __pos__(self): + return self + def __invert__(self): return Operator("~", [self]) def __neg__(self): diff --git a/tests/test_hdl_ast.py b/tests/test_hdl_ast.py index 38502e1..6bc7f49 100644 --- a/tests/test_hdl_ast.py +++ b/tests/test_hdl_ast.py @@ -397,6 +397,9 @@ class OperatorTestCase(FHDLTestCase): self.assertEqual(repr(v), "(s (const 4'd1))") self.assertEqual(v.shape(), signed(4)) + def test_pos(self): + self.assertRepr(+Const(10), "(const 4'd10)") + def test_neg(self): v1 = -Const(0, unsigned(4)) self.assertEqual(repr(v1), "(- (const 4'd0))")