hdl.ast: guard rotate_* against 0-width values.

Fixes #808.
This commit is contained in:
Marcelina Kościelnicka 2023-06-07 12:49:41 +02:00 committed by Catherine
parent 656db317d2
commit a6e33abc5f
2 changed files with 12 additions and 2 deletions

View file

@ -516,7 +516,8 @@ class Value(metaclass=ABCMeta):
"""
if not isinstance(amount, int):
raise TypeError("Rotate amount must be an integer, not {!r}".format(amount))
amount %= len(self)
if len(self) != 0:
amount %= len(self)
return Cat(self[-amount:], self[:-amount]) # meow :3
def rotate_right(self, amount):
@ -534,7 +535,8 @@ class Value(metaclass=ABCMeta):
"""
if not isinstance(amount, int):
raise TypeError("Rotate amount must be an integer, not {!r}".format(amount))
amount %= len(self)
if len(self) != 0:
amount %= len(self)
return Cat(self[amount:], self[:amount])
def eq(self, value):