diff --git a/amaranth/hdl/_ir.py b/amaranth/hdl/_ir.py index e86171293..ee877541f 100644 --- a/amaranth/hdl/_ir.py +++ b/amaranth/hdl/_ir.py @@ -557,6 +557,7 @@ def _assign_port_names(self): if name is None: name = _add_name(assigned_names, conn.name) assigned_names.add(name) + validate_name(name, "Top-level port name") new_ports.append((name, conn, dir)) self.ports = new_ports diff --git a/tests/test_hdl_ir.py b/tests/test_hdl_ir.py index 36fe62f03..f4d9df58f 100644 --- a/tests/test_hdl_ir.py +++ b/tests/test_hdl_ir.py @@ -1044,6 +1044,12 @@ def test_assign_names_to_fragments_duplicate(self): self.assertEqual(design.fragments[a1_f].name, ("top", "a")) self.assertEqual(design.fragments[a2_f].name, ("top", "a$1")) + def test_port_wrong_name(self): + f = Fragment() + with self.assertRaisesRegex(NameError, + r"^Top-level port name must be a non-empty string$"): + design = Design(f, ports=[("", Signal(), None)], hierarchy=("top",)) + class ElaboratesTo(Elaboratable): def __init__(self, lower):