hdl.ast: change warning on out-of-range reset to an error, improve it.

Fixes #1019.
This commit is contained in:
Wanda 2024-01-29 19:18:18 +01:00 committed by Catherine
parent 8501d9dd73
commit e9299ccd0e
3 changed files with 25 additions and 12 deletions

View file

@ -1106,10 +1106,8 @@ class SignalTestCase(FHDLTestCase):
self.assertEqual(s8.shape(), signed(5))
s9 = Signal(range(-20, 16))
self.assertEqual(s9.shape(), signed(6))
with warnings.catch_warnings():
warnings.filterwarnings(action="ignore", category=SyntaxWarning)
s10 = Signal(range(0))
self.assertEqual(s10.shape(), unsigned(0))
s10 = Signal(range(0))
self.assertEqual(s10.shape(), unsigned(0))
s11 = Signal(range(1))
self.assertEqual(s11.shape(), unsigned(1))
@ -1184,10 +1182,22 @@ class SignalTestCase(FHDLTestCase):
Signal(signed(1), reset=-2)
def test_reset_wrong_fencepost(self):
with self.assertWarnsRegex(SyntaxWarning,
with self.assertRaisesRegex(SyntaxError,
r"^Reset value 10 equals the non-inclusive end of the signal shape "
r"range\(0, 10\); this is likely an off-by-one error$"):
Signal(range(0, 10), reset=10)
with self.assertRaisesRegex(SyntaxError,
r"^Reset value 0 equals the non-inclusive end of the signal shape "
r"range\(0, 0\); this is likely an off-by-one error$"):
Signal(range(0), reset=0)
def test_reset_wrong_range(self):
with self.assertRaisesRegex(SyntaxError,
r"^Reset value 11 is not within the signal shape range\(0, 10\)$"):
Signal(range(0, 10), reset=11)
with self.assertRaisesRegex(SyntaxError,
r"^Reset value 0 is not within the signal shape range\(1, 10\)$"):
Signal(range(1, 10), reset=0)
def test_attrs(self):
s1 = Signal()