From de6b69370fb58291f62e0e0e09b9b2d061a87037 Mon Sep 17 00:00:00 2001 From: Arusekk Date: Sun, 22 Jan 2023 23:05:54 +0100 Subject: [PATCH] hdl.ast: Do not warn on int Enums in Cat. This aligns with the behavior for plain Enums. --- amaranth/hdl/ast.py | 2 +- tests/test_hdl_ast.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/amaranth/hdl/ast.py b/amaranth/hdl/ast.py index 9dc7cff..586fbb3 100644 --- a/amaranth/hdl/ast.py +++ b/amaranth/hdl/ast.py @@ -860,7 +860,7 @@ class Cat(Value): super().__init__(src_loc_at=src_loc_at) self.parts = [] for index, arg in enumerate(flatten(args)): - if isinstance(arg, int) and arg not in [0, 1]: + if isinstance(arg, int) and not isinstance(arg, Enum) and arg not in [0, 1]: warnings.warn("Argument #{} of Cat() is a bare integer {} used in bit vector " "context; consider specifying explicit width using C({}, {}) instead" .format(index + 1, arg, arg, bits_for(arg)), diff --git a/tests/test_hdl_ast.py b/tests/test_hdl_ast.py index 71453de..b0cd9b2 100644 --- a/tests/test_hdl_ast.py +++ b/tests/test_hdl_ast.py @@ -801,6 +801,15 @@ class CatTestCase(FHDLTestCase): c = Cat(Color.RED, Color.BLUE) self.assertEqual(repr(c), "(cat (const 2'd1) (const 2'd2))") + def test_intenum(self): + class Color(int, Enum): + RED = 1 + BLUE = 2 + with warnings.catch_warnings(): + warnings.filterwarnings(action="error", category=SyntaxWarning) + c = Cat(Color.RED, Color.BLUE) + self.assertEqual(repr(c), "(cat (const 2'd1) (const 2'd2))") + def test_int_wrong(self): with self.assertWarnsRegex(SyntaxWarning, r"^Argument #1 of Cat\(\) is a bare integer 2 used in bit vector context; "