Repository: amaranth-lang/amaranth
Pull request #1283 (2024-04-04 23:06:49)

hdl._ir: fix `SwitchValue` LHS lowering.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/amaranth-lang/amaranth/pull/1283?dropdown=coverage&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:
> Project coverage is 90.94%. Comparing base [(`572d546`)](https://app.codecov.io/gh/amaranth-lang/amaranth/commit/572d546e07ae2b5437921d50edbbaf056e2f4081?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=amaranth-lang) to head [(`d37a498`)](https://app.codecov.io/gh/amaranth-lang/amaranth/pull/1283?dropdown=coverage&src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=amaranth-lang).


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


```diff
@@            Coverage Diff             @@
##             main    #1283      +/-   ##
==========================================
+ Coverage   90.90%   90.94%   +0.03%     
==========================================
  Files          44       44              
  Lines       10588    10588              
  Branches     2583     2583              
==========================================
+ Hits         9625     9629       +4     
+ Misses        776      773       -3     
+ Partials      187      186       -1     
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/amaranth-lang/amaranth/pull/1283?dropdown=coverage&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/hdl/_ir.py b/amaranth/hdl/_ir.py
index a853733..be0c4da 100644
--- a/amaranth/hdl/_ir.py
+++ b/amaranth/hdl/_ir.py
@@ -1076,7 +1076,7 @@ class NetlistEmitter:
                     conds.append(_nir.Net.from_const(1))
                 elems.append(elem)
             conds = _nir.Value(conds)
-            cell = _nir.PriorityMatch(module_idx, en=_nir.Net.from_const(1),
+            cell = _nir.PriorityMatch(module_idx, en=cond,
                                       inputs=conds, src_loc=lhs.src_loc)
             conds = self.netlist.add_value_cell(len(conds), cell)
             for subcond, val in zip(conds, elems):


Test patch:
diff --git a/tests/test_hdl_ir.py b/tests/test_hdl_ir.py
index 516898e..0483d7a 100644
--- a/tests/test_hdl_ir.py
+++ b/tests/test_hdl_ir.py
@@ -1662,6 +1662,41 @@ class AssignTestCase(FHDLTestCase):
         )
         """)
 
+    def test_mux_en(self):
+        s1 = Signal(8)
+        s2 = Signal(8)
+        s3 = Signal(8)
+        s4 = Signal(8)
+        en = Signal()
+        m = Module()
+        with m.If(en):
+            m.d.comb += Mux(s1, s2, s3).eq(s4)
+        nl = build_netlist(Fragment.get(m, None), ports=[s1, s2, s3, s4, en])
+        self.assertRepr(nl, """
+        (
+            (module 0 None ('top')
+                (input 's1' 0.2:10)
+                (input 's4' 0.10:18)
+                (input 'en' 0.18)
+                (output 's2' 6.0:8)
+                (output 's3' 5.0:8)
+            )
+            (cell 0 0 (top
+                (input 's1' 2:10)
+                (input 's4' 10:18)
+                (input 'en' 18:19)
+                (output 's2' 6.0:8)
+                (output 's3' 5.0:8)
+            ))
+            (cell 1 0 (matches 0.18 1))
+            (cell 2 0 (priority_match 1 1.0))
+            (cell 3 0 (matches 0.2:10 00000000))
+            (cell 4 0 (priority_match 2.0 (cat 3.0 1'd1)))
+            (cell 5 0 (assignment_list 8'd0 (4.0 0:8 0.10:18)))
+            (cell 6 0 (assignment_list 8'd0 (4.1 0:8 0.10:18)))
+        )
+        """)
+
     def test_sliced_slice(self):
         s1 = Signal(12)
         s2 = Signal(4)