Open
Description
Version Information
- vyper Version (output of
vyper --version
): 0.4.1 - OS: linux
- Python Version (output of
python --version
): 3.12
What's your issue about?
Using slice
with a String[N]
variable uses the string's actual length rather than the specified N
.
For instance:
@view
@external
def foo() -> String[5]:
id_label: String[78] = uint2str(123)
short_id: String[5] = slice(id_label, 0, 5)
return short_id
Will revert, but:
@view
@external
def foo() -> String[5]:
id_label: String[78] = uint2str(123456)
short_id: String[5] = slice(id_label, 0, 5)
return short_id
will work fine.
Both use String[78]
for id_label. The only difference is the runtime length: "123" vs "123456".
I'd expect in both cases slice(id_label, 0, 5)
should succeed.
You could check the length and use convert
but it's not great UX