hdl.ast: fix Array not being indexable by ValueCastable
This commit is contained in:
parent
5d9ad62f36
commit
cc9fe89049
|
@ -1382,6 +1382,8 @@ class Array(MutableSequence):
|
|||
self._mutable = True
|
||||
|
||||
def __getitem__(self, index):
|
||||
if isinstance(index, ValueCastable):
|
||||
index = Value.cast(index)
|
||||
if isinstance(index, Value):
|
||||
if self._mutable:
|
||||
self._proxy_at = tracer.get_src_loc()
|
||||
|
|
|
@ -1005,6 +1005,18 @@ class ArrayTestCase(FHDLTestCase):
|
|||
r"^Array can no longer be mutated after it was indexed with a value at "):
|
||||
a.insert(1, 2)
|
||||
|
||||
def test_index_value_castable(self):
|
||||
class MyValue(ValueCastable):
|
||||
@ValueCastable.lowermethod
|
||||
def as_value(self):
|
||||
return Signal()
|
||||
|
||||
def shape():
|
||||
return unsigned(1)
|
||||
|
||||
a = Array([1,2,3])
|
||||
a[MyValue()]
|
||||
|
||||
def test_repr(self):
|
||||
a = Array([1,2,3])
|
||||
self.assertEqual(repr(a), "(array mutable [1, 2, 3])")
|
||||
|
|
Loading…
Reference in a new issue