Repository: amaranth-lang/amaranth (python)

Issue:
Connect statements such as `wiring.connect(wiring.flipped(self.write), inner.w_stream)` silently do nothing
Note the missing first argument `m`.

This has cost me half a hour of bug searching :(

Pull request:
lib.wiring: check type of `m` in `connect(m, ...)`
This error is very difficult to catch otherwise.

Fixes #1435.

Patch:
diff --git a/amaranth/lib/wiring.py b/amaranth/lib/wiring.py
index b91a0e7..4a08469 100644
--- a/amaranth/lib/wiring.py
+++ b/amaranth/lib/wiring.py
@@ -5,6 +5,7 @@ import warnings
 
 from .. import tracer
 from ..hdl._ast import Shape, ShapeCastable, Const, Signal, Value, ValueCastable
+from ..hdl._dsl import Module
 from ..hdl._ir import Elaboratable
 from .._utils import final
 from .meta import Annotation, InvalidAnnotation
@@ -1401,6 +1402,9 @@ def connect(m, *args, **kwargs):
     a connection cannot be made.
     """
 
+    if not isinstance(m, Module):
+        raise TypeError(f"The initial argument must be a module, not {m!r}")
+
     objects = {
         **{index:   arg for index,   arg in enumerate(args)},
         **{keyword: arg for keyword, arg in kwargs.items()}


Test patch:
diff --git a/tests/test_lib_wiring.py b/tests/test_lib_wiring.py
index 79f96e2..eb26390 100644
--- a/tests/test_lib_wiring.py
+++ b/tests/test_lib_wiring.py
@@ -1045,6 +1045,15 @@ class ConnectTestCase(unittest.TestCase):
                      a=Signal(),
                      b=Signal()))
 
+    def test_bug_1435_missing_module(self):
+        sig = Signature({"a": Out(1)})
+        p = sig.create()
+        q = sig.flip().create()
+
+        with self.assertRaisesRegex(TypeError,
+                r"^The initial argument must be a module, not <PureInterface: .+>$"):
+            connect(p, q)
+
 
 class ComponentTestCase(unittest.TestCase):
     def test_basic(self):