Skip to content

Commit

Permalink
hdl.ast: Do not warn on int Enums in Cat.
Browse files Browse the repository at this point in the history
This aligns with the behavior for plain Enums.
  • Loading branch information
Arusekk authored and whitequark committed Jan 22, 2023
1 parent 58a0c68 commit de6b693
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion amaranth/hdl/ast.py
Expand Up @@ -860,7 +860,7 @@ def __init__(self, *args, src_loc_at=0):
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)),
Expand Down
9 changes: 9 additions & 0 deletions tests/test_hdl_ast.py
Expand Up @@ -801,6 +801,15 @@ class Color(Enum):
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; "
Expand Down

0 comments on commit de6b693

Please sign in to comment.