Skip to content

Commit a74cacd

Browse files
author
whitequark
committed
hdl.ast: handle a common typo, such as Signal(1, True).
1 parent c9c9307 commit a74cacd

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

nmigen/hdl/ast.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,8 @@ def __init__(self, shape=None, name=None, reset=0, reset_less=False, min=None, m
581581
attrs=None, decoder=None, src_loc_at=0):
582582
super().__init__(src_loc_at=src_loc_at)
583583

584+
if name is not None and not isinstance(name, str):
585+
raise TypeError("Name must be a string, not '{!r}'".format(name))
584586
self.name = name or tracer.get_var_name(depth=2 + src_loc_at, default="$signal")
585587

586588
if shape is None:

nmigen/test/test_hdl_ast.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,12 @@ def test_name(self):
429429
s2 = Signal(name="sig")
430430
self.assertEqual(s2.name, "sig")
431431

432+
def test_name_bad(self):
433+
with self.assertRaises(TypeError,
434+
msg="Name must be a string, not 'True'"):
435+
# A common typo: forgetting to put parens around width and signedness
436+
Signal(1, True)
437+
432438
def test_reset(self):
433439
s1 = Signal(4, reset=0b111, reset_less=True)
434440
self.assertEqual(s1.reset, 0b111)

0 commit comments

Comments
 (0)