From 019cbb22c7e019ab239eb0b3e9f9a3fa193934a5 Mon Sep 17 00:00:00 2001 From: whitequark Date: Wed, 2 Oct 2019 08:24:37 +0000 Subject: [PATCH] hdl.ast: don't crash on Mux(, ...). Fixes #240. --- nmigen/hdl/ast.py | 3 ++- nmigen/test/test_hdl_ast.py | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/nmigen/hdl/ast.py b/nmigen/hdl/ast.py index 6a68a67..6175300 100644 --- a/nmigen/hdl/ast.py +++ b/nmigen/hdl/ast.py @@ -526,8 +526,9 @@ def Mux(sel, val1, val0): Value, out Output ``Value``. If ``sel`` is asserted, the Mux returns ``val1``, else ``val0``. """ + sel = Value.wrap(sel) if len(sel) != 1: - sel = Value.wrap(sel).bool() + sel = sel.bool() return Operator("m", [sel, val1, val0]) diff --git a/nmigen/test/test_hdl_ast.py b/nmigen/test/test_hdl_ast.py index 0c4914b..f90d444 100644 --- a/nmigen/test/test_hdl_ast.py +++ b/nmigen/test/test_hdl_ast.py @@ -292,6 +292,10 @@ class OperatorTestCase(FHDLTestCase): v = Mux(s, Const(0, (4, False)), Const(0, (6, False))) self.assertEqual(repr(v), "(m (b (const 3'd4)) (const 4'd0) (const 6'd0))") + def test_mux_bool(self): + v = Mux(True, Const(0), Const(0)) + self.assertEqual(repr(v), "(m (const 1'd1) (const 1'd0) (const 1'd0))") + def test_bool(self): v = Const(0).bool() self.assertEqual(repr(v), "(b (const 1'd0))") -- 2.30.2