Skip to content

Commit 625dac3

Browse files
wanda-phiwhitequark
authored andcommitted
hdl._dsl: improve error message on m.domains.cd_foo = ....
Fixes #1331.
1 parent 8c1c9f2 commit 625dac3

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

amaranth/hdl/_dsl.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,11 @@ def __setattr__(self, name, domain):
191191
raise TypeError("Only clock domains may be added to `m.domains`, not {!r}"
192192
.format(domain))
193193
if domain.name != name:
194-
raise NameError("Clock domain name {!r} must match name in `m.domains.{} += ...` "
195-
"syntax"
196-
.format(domain.name, name))
194+
if name == "cd_" + domain.name:
195+
raise NameError(f"Domain name should not be prefixed with 'cd_' in `m.domains`, "
196+
f"use `m.domains.{domain.name} = ...` instead")
197+
raise NameError(f"Clock domain name {domain.name!r} must match name in "
198+
f"`m.domains.{name} = ...` syntax")
197199
self._builder._add_domain(domain)
198200

199201

tests/test_hdl_dsl.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ def test_domain_add_wrong(self):
930930
def test_domain_add_wrong_name(self):
931931
m = Module()
932932
with self.assertRaisesRegex(NameError,
933-
r"^Clock domain name 'bar' must match name in `m\.domains\.foo \+= \.\.\.` syntax$"):
933+
r"^Clock domain name 'bar' must match name in `m\.domains\.foo = \.\.\.` syntax$"):
934934
m.domains.foo = ClockDomain("bar")
935935

936936
def test_domain_add_wrong_duplicate(self):
@@ -968,3 +968,10 @@ def test_lower(self):
968968
)
969969
""")
970970
self.assertEqual(len(f2.subfragments), 0)
971+
972+
def test_bug_1331(self):
973+
m = Module()
974+
with self.assertRaisesRegex(NameError,
975+
r"^Domain name should not be prefixed with 'cd_' in `m.domains`, "
976+
r"use `m.domains.rx = ...` instead$"):
977+
m.domains.cd_rx = ClockDomain()

0 commit comments

Comments
 (0)