hdl.ast: warn on fencepost error in Signal(range(x), reset=x).
Also, relax the language reference inset from "warning" to "note" since this is no longer something developers have to keep in mind explicitly.
This commit is contained in:
parent
32eabd9372
commit
80343d1c4c
3 changed files with 33 additions and 4 deletions
|
|
@ -357,6 +357,12 @@ class ConstTestCase(FHDLTestCase):
|
|||
r"^Width must be a non-negative integer, not -1$"):
|
||||
Const(1, -1)
|
||||
|
||||
def test_wrong_fencepost(self):
|
||||
with self.assertWarnsRegex(SyntaxWarning,
|
||||
r"^Value 10 equals the non-inclusive end of the constant shape "
|
||||
r"range\(0, 10\); this is likely an off-by-one error$"):
|
||||
Const(10, range(10))
|
||||
|
||||
def test_normalization(self):
|
||||
self.assertEqual(Const(0b10110, signed(5)).value, -10)
|
||||
|
||||
|
|
@ -961,8 +967,10 @@ class SignalTestCase(FHDLTestCase):
|
|||
self.assertEqual(s8.shape(), signed(5))
|
||||
s9 = Signal(range(-20, 16))
|
||||
self.assertEqual(s9.shape(), signed(6))
|
||||
s10 = Signal(range(0))
|
||||
self.assertEqual(s10.shape(), unsigned(0))
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings(action="ignore", category=SyntaxWarning)
|
||||
s10 = Signal(range(0))
|
||||
self.assertEqual(s10.shape(), unsigned(0))
|
||||
s11 = Signal(range(1))
|
||||
self.assertEqual(s11.shape(), unsigned(1))
|
||||
|
||||
|
|
@ -1006,6 +1014,12 @@ class SignalTestCase(FHDLTestCase):
|
|||
r"^Reset value -2 will be truncated to the signal shape signed\(1\)$"):
|
||||
Signal(signed(1), reset=-2)
|
||||
|
||||
def test_reset_wrong_fencepost(self):
|
||||
with self.assertWarnsRegex(SyntaxWarning,
|
||||
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)
|
||||
|
||||
def test_attrs(self):
|
||||
s1 = Signal()
|
||||
self.assertEqual(s1.attrs, {})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue