diff --git a/magma/tuple.py b/magma/tuple.py index f21ada6a4..2e15c4632 100644 --- a/magma/tuple.py +++ b/magma/tuple.py @@ -320,7 +320,7 @@ def wire(self, o, debug_info): ) return - if self.keys() != o.keys(): + if list(self.keys()) != list(o.keys()): _logger.error( WiringLog(f"Cannot wire {{}} (type={type(o)}, " f"keys={list(self.keys())}) to " diff --git a/tests/test_type/test_tuple.py b/tests/test_type/test_tuple.py index d4377f41d..45ea260f5 100644 --- a/tests/test_type/test_tuple.py +++ b/tests/test_type/test_tuple.py @@ -2,6 +2,7 @@ import magma as m from magma import * +from magma.testing.utils import has_error def test_pair(): @@ -357,3 +358,19 @@ class Foo(m.Circuit): assert io.I.y.value() is u.y assert not caplog.messages, "Should not raise wiring errors" + + +def test_tuple_key_ordering(caplog): + T0 = m.AnonProduct[{"x": m.Bit, "y": m.Bits[8]}] + T1 = m.AnonProduct[{"y": m.Bits[8], "x": m.Bit}] + + class tuple_key_ordering(m.Circuit): + io = m.IO(I=m.In(T0), O=m.Out(T1)) + io.O @= io.I + + msg = """\ +\033[1mtests/test_type/test_tuple.py:368\033[0m: Cannot wire tuple_key_ordering.I (type=Tuple(x=Out(Bit),y=Out(Bits[8])), keys=['y', 'x']) to tuple_key_ordering.O (type=Tuple(y=In(Bits[8]),x=In(Bit)), keys=['x', 'y']) because the tuples do not have the same keys +>> io.O @= io.I\ +""" + + assert has_error(caplog, "")