Skip to content

Commit cb91165

Browse files
committed
lib.wiring: check type of m in connect(m, ...).
This error is very difficult to catch otherwise. Fixes #1435.
1 parent dfef3bc commit cb91165

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

amaranth/lib/wiring.py

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from .. import tracer
77
from ..hdl._ast import Shape, ShapeCastable, Const, Signal, Value, ValueCastable
8+
from ..hdl._dsl import Module
89
from ..hdl._ir import Elaboratable
910
from .._utils import final
1011
from .meta import Annotation, InvalidAnnotation
@@ -1401,6 +1402,9 @@ def connect(m, *args, **kwargs):
14011402
a connection cannot be made.
14021403
"""
14031404

1405+
if not isinstance(m, Module):
1406+
raise TypeError(f"The initial argument must be a module, not {m!r}")
1407+
14041408
objects = {
14051409
**{index: arg for index, arg in enumerate(args)},
14061410
**{keyword: arg for keyword, arg in kwargs.items()}

tests/test_lib_wiring.py

+9
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,15 @@ def test_connect_multi_some_in_pairs(self):
10451045
a=Signal(),
10461046
b=Signal()))
10471047

1048+
def test_bug_1435_missing_module(self):
1049+
sig = Signature({"a": Out(1)})
1050+
p = sig.create()
1051+
q = sig.flip().create()
1052+
1053+
with self.assertRaisesRegex(TypeError,
1054+
r"^The initial argument must be a module, not <PureInterface: .+>$"):
1055+
connect(p, q)
1056+
10481057

10491058
class ComponentTestCase(unittest.TestCase):
10501059
def test_basic(self):

0 commit comments

Comments
 (0)