hdl.ast: Do not warn on int Enums in Cat.

This aligns with the behavior for plain Enums.
This commit is contained in:
Arusekk 2023-01-22 23:05:54 +01:00 committed by Catherine
parent 58a0c68279
commit de6b69370f
2 changed files with 10 additions and 1 deletions

View file

@ -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)),

View file

@ -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; "