Repository: amaranth-lang/amaranth
Pull request #969 (2023-11-26 18:14:55)

lib.io: fix Pin.eq to work when FlippedInterface is involved.
This was broken by #915, when platform started handing out `FlippedInterface` versions of `Pin`.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/amaranth-lang/amaranth/pull/969?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=amaranth-lang) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Comparison is base [(`74e613b`)](https://app.codecov.io/gh/amaranth-lang/amaranth/commit/74e613b49d89356db73687fd2f0bbd8290158291?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=amaranth-lang) 83.72% compared to head [(`5b1bfd7`)](https://app.codecov.io/gh/amaranth-lang/amaranth/pull/969?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=amaranth-lang) 83.66%.


<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main     #969      +/-   ##
==========================================
- Coverage   83.72%   83.66%   -0.06%     
==========================================
  Files          54       54              
  Lines        7809     7811       +2     
  Branches     1912     1659     -253     
==========================================
- Hits         6538     6535       -3     
- Misses       1062     1063       +1     
- Partials      209      213       +4     
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/amaranth-lang/amaranth/pull/969?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=amaranth-lang).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=amaranth-lang).


Patch:
diff --git a/amaranth/lib/io.py b/amaranth/lib/io.py
index a208163..54bd9c0 100644
--- a/amaranth/lib/io.py
+++ b/amaranth/lib/io.py
@@ -4,7 +4,7 @@ from .. import *
 with warnings.catch_warnings():
     warnings.filterwarnings(action="ignore", category=DeprecationWarning)
     from ..hdl.rec import *
-from ..lib.wiring import In, Out, Signature
+from ..lib.wiring import In, Out, Signature, flipped, FlippedInterface
 
 
 __all__ = ["pin_layout", "Pin"]
@@ -135,4 +135,7 @@ class Pin(Record):
         first_field, _, _ = next(iter(Pin(1, dir="o").layout))
         warnings.warn(f"`pin.eq(...)` is deprecated; use `pin.{first_field}.eq(...)` here",
                       DeprecationWarning, stacklevel=2)
-        return super().eq(other)
+        if isinstance(self, FlippedInterface):
+            return Record.eq(flipped(self), other)
+        else:
+            return Record.eq(self, other)


Test patch:
diff --git a/tests/test_build_res.py b/tests/test_build_res.py
index b017c6e..edb32a0 100644
--- a/tests/test_build_res.py
+++ b/tests/test_build_res.py
@@ -315,3 +315,12 @@ class ResourceManagerTestCase(FHDLTestCase):
                 (r"^Cannot add clock constraint on \(sig clk100_0__i\), which is already "
                     r"constrained to 100000000\.0 Hz$")):
             self.cm.add_clock_constraint(clk100.i, 1e6)
+
+    def test_eq_deprecation(self):
+        user_led = self.cm.request("user_led", 0)
+        m = Module()
+        with self.assertWarns(DeprecationWarning):
+            m.d.sync += user_led.eq(1)
+        p = Pin(4, "o")
+        with self.assertWarns(DeprecationWarning):
+            m.d.sync += p.eq(1)