hdl.ast: suggest bit_select or word_select when indexing with Value.

Fixes #1044.
This commit is contained in:
Wanda 2024-01-18 21:00:48 +01:00 committed by Catherine
parent 9e9790377a
commit b40c18fb00
2 changed files with 13 additions and 0 deletions

View file

@ -370,10 +370,14 @@ class Value(metaclass=ABCMeta):
key += n
return Slice(self, key, key + 1, src_loc_at=1)
elif isinstance(key, slice):
if isinstance(key.start, Value) or isinstance(key.stop, Value):
raise TypeError(f"Cannot slice value with a value; use Value.bit_select() or Value.word_select() instead")
start, stop, step = key.indices(n)
if step != 1:
return Cat(self[i] for i in range(start, stop, step))
return Slice(self, start, stop, src_loc_at=1)
elif isinstance(key, Value):
raise TypeError(f"Cannot index value with a value; use Value.bit_select() instead")
else:
raise TypeError(f"Cannot index value with {key!r}")