Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion amaranth/hdl/_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -2052,7 +2052,7 @@ def __init__(self, shape=None, *, name=None, init=None, reset=None, reset_less=F
.format(orig_init, shape),
category=SyntaxWarning,
stacklevel=2)
self._init = init.value
self._init = Const(init.value, shape).value
self._reset_less = bool(reset_less)

if isinstance(orig_shape, range) and orig_init is not None and orig_init not in orig_shape:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_hdl_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,14 @@ def test_init_wrong_too_wide(self):
r"^Initial value -2 will be truncated to the signal shape signed\(1\)$"):
Signal(signed(1), init=-2)

def test_init_truncated(self):
s1 = Signal(unsigned(2), init=-1)
self.assertEqual(s1.init, 0b11)
with warnings.catch_warnings():
warnings.filterwarnings(action="ignore", category=SyntaxWarning)
s2 = Signal(signed(2), init=-33)
self.assertEqual(s2.init, -1)

def test_init_wrong_fencepost(self):
with self.assertRaisesRegex(SyntaxError,
r"^Initial value 10 equals the non-inclusive end of the signal shape "
Expand Down