hdl.ast: check type of Sample(domain=...).

Fixes #199.
This commit is contained in:
whitequark 2019-09-08 23:55:05 +00:00
parent 3f6abc0b7a
commit 9b398b502e
2 changed files with 10 additions and 2 deletions

View file

@ -983,11 +983,14 @@ class Sample(Value):
self.clocks = int(clocks)
self.domain = domain
if not isinstance(self.value, (Const, Signal, ClockSignal, ResetSignal, Initial)):
raise TypeError("Sampled value may only be a signal or a constant, not {!r}"
raise TypeError("Sampled value must be a signal or a constant, not {!r}"
.format(self.value))
if self.clocks < 0:
raise ValueError("Cannot sample a value {} cycles in the future"
.format(-self.clocks))
if not (self.domain is None or isinstance(self.domain, str)):
raise TypeError("Domain name must be a string or None, not {!r}"
.format(self.domain))
def shape(self):
return self.value.shape()

View file

@ -629,7 +629,7 @@ class SampleTestCase(FHDLTestCase):
def test_wrong_value_operator(self):
with self.assertRaises(TypeError,
"Sampled value may only be a signal or a constant, not "
"Sampled value must be a signal or a constant, not "
"(+ (sig $signal) (const 1'd1))"):
Sample(Signal() + 1, 1, "sync")
@ -638,6 +638,11 @@ class SampleTestCase(FHDLTestCase):
"Cannot sample a value 1 cycles in the future"):
Sample(Signal(), -1, "sync")
def test_wrong_domain(self):
with self.assertRaises(TypeError,
"Domain name must be a string or None, not 0"):
Sample(Signal(), 1, 0)
class InitialTestCase(FHDLTestCase):
def test_initial(self):