lib.data: at most one Union
field can have annotation with a default.
This commit is contained in:
parent
e2ce959c90
commit
ae1aeff0f2
|
@ -419,6 +419,11 @@ class _AggregateMeta(ShapeCastable, type):
|
|||
if name in namespace:
|
||||
reset[name] = namespace.pop(name)
|
||||
cls = type.__new__(metacls, name, bases, namespace)
|
||||
if cls.__layout_cls is UnionLayout:
|
||||
if len(reset) > 1:
|
||||
raise ValueError("Reset value for at most one field can be provided for "
|
||||
"a union class (specified: {})"
|
||||
.format(", ".join(reset.keys())))
|
||||
cls.__layout = cls.__layout_cls(layout)
|
||||
cls.__reset = reset
|
||||
return cls
|
||||
|
|
|
@ -679,6 +679,14 @@ class UnionTestCase(FHDLTestCase):
|
|||
self.assertEqual(s.attrs, {"debug": 1})
|
||||
self.assertEqual(s.decoder, decoder)
|
||||
|
||||
def test_define_reset_two_wrong(self):
|
||||
with self.assertRaisesRegex(ValueError,
|
||||
r"^Reset value for at most one field can be provided for a union class "
|
||||
r"\(specified: a, b\)$"):
|
||||
class U(Union):
|
||||
a: unsigned(1) = 1
|
||||
b: unsigned(2) = 1
|
||||
|
||||
def test_construct_reset_two_wrong(self):
|
||||
class U(Union):
|
||||
a: unsigned(1)
|
||||
|
|
Loading…
Reference in a new issue