Skip to content

lib.wiring: check type of m in connect(m, ...) [0.5 backport] #1437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions amaranth/lib/wiring.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

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
Expand Down Expand Up @@ -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()}
Expand Down
9 changes: 9 additions & 0 deletions tests/test_lib_wiring.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,15 @@ def test_connect_multi_some_in_pairs(self):
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):
Expand Down