diff --git a/amaranth/hdl/_ir.py b/amaranth/hdl/_ir.py index e5af19dd8..e435deac3 100644 --- a/amaranth/hdl/_ir.py +++ b/amaranth/hdl/_ir.py @@ -559,6 +559,7 @@ def _assign_port_names(self): raise TypeError("Signals with private names cannot be used in unnamed top-level ports") 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 03cb9a03e..50c760456 100644 --- a/tests/test_hdl_ir.py +++ b/tests/test_hdl_ir.py @@ -1054,6 +1054,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):