elvish
elvish copied to clipboard
`..=` slicing exception messages are misleading
~~Currently has-key tries to parse slices the same way as indexing does. This leads to this:~~
~> has-key [a b c d] -1..4
▶ $true
~~In my opinion it shouldn't — has-key should have stricter checks than indexing.
Discovered in #1647.~~
Scratch that, I misunderstood how the indexing is supposed to work.
There is a slightly different issue, however:
~> put [a b c d][0..=4]
Exception: out of range: index must be from 0 to 4, but is 5
I don't think this error message should add one in this way. Let me convert this issue into an error message improvement proposal, then.
Some more peculiarities with the same cause:
~> put [a b c d][4..=-4]
Exception: out of range: negative slice upper index must be from 0 to -1, but is -3
~> put [a b c d][4..=0] # since 0 is indicated as valid above
Exception: out of range: slice upper index must be from 4 to 4, but is 1
~> put [a b c d][3..=-3]
Exception: out of range: negative slice upper index must be from -1 to -1, but is -2
~> put [a b c d][3..=-2] # should be invalid, because it's not from -1 to -1
▶ []