Closed Hirevo closed 2 years ago
These changes do not break anything in the test suite but I wonder whether any of these is actually a breaking change for some other SOM code somewhere that I am not aware of.
Also, maybe these behaviours are intended to be that way, in which case, I have no issues dropping the PR.
Absence of test failure is probably not a good indicator, since coverage isn't great. I'll probably not get to any of these PRs this week anymore. Sorry. Will need to take a closer look to be sure what's going on.
Also, I should say: thanks a lot for all this stuff. It's greatly appreciated!
@Hirevo could you either pull the tests from here: https://github.com/Hirevo/SOM/compare/fix/vector-indices...smarr:fix/vector-indices?expand=1, or tick the "maintainers can push" box, I think on the right of the PR somewhere.
This adds a small clarification in the code, as well as a bunch of unit tests.
Thanks!
Th UI seems to tell me that pushes from maintainers are already allowed (the checkbox on the right was already checked).
In any case, I think I may be able to cherry-pick your commits into this branch.
Cherry-picking the commits seems to have done the trick.
Thank you!
As I was continuing to use the
Vector
class more and more intensely when solving the Advent of Code puzzles, I discovered some more potential issues about howVector
behaves after a call toVector>>#removeFirst
, specifically around the indices that it uses and/or allows.After a single call to
Vector>>#removeFirst
for example, the current behaviour is that:Vector>>#doIndexes:
will give indices starting from2
(the value of itsfirst
variable), instead of1
.Vector>>#asArray
will start indexing out of bounds of its temporary array as it is filling it in, resulting in somenil
values in its output array.Vector>>#at:
andVector>>#at:put:
will do nothing (that is observable to the caller) on index1
(because it is now less thanfirst
)This PR fixes these issues and makes it so that the user always uses and observes indices starting from 1 onwards (the vector takes care of making it relative to
first
when indexing intostorage
).And another unrelated bug fix that I have included here is that an off-by-one access past the end of the vector simply always returned nil, instead of calling
Object>>#error:
(which is invoked starting from off-by-two errors).Here is some code that shows the bugs: