Repository navigation
Fix roll panic on empty lists and records - #19285
Conversation
`roll up`, `roll down`, `roll left` and `roll right` computed `n % len` on the input, which divides by zero for an empty list or an empty record. The default case of `by` also asked the standard library to rotate an empty slice by one, which asserts. Return empty input unchanged and add regression tests for each direction. Signed-off-by: manoj-1407 <[email protected]> Signed-off-by: G. Manoj Kumar <[email protected]>
There was a problem hiding this comment.
Review overview
🟡 Changes recommended
The early returns fix all three panics from the description. The notes below are a simpler way to write the guard and sharper test assertions, none of them blocking.
Findings: 0
Open (5)
Onechecked_remcovers both panics The comment names only one of the two panics Assert on the value instead of== [] Test a table with one empty rowroll up/roll downcopy the whole list. Not for this PR: line 40 rotatesvals.to_mut()in place, thenvalues.to_owned()clones every row into a newVec. Takingvals.into_owned(), rotating thatVecand passing it toValue::listskips the copy.
Notes from my clanker, checked on 7a4ee4b. Read-only, branch not built; CI is green on all 12 checks. The checked_rem rotation was compared against the current expression with a standalone script (lengths 0-3, --by none/0/1/3/7).
Use `checked_rem` so an empty list or record rotates by zero instead of special-casing it, which also covers the default rotation. Compare the rolled value in the empty-input tests, and add a table test where only one row is empty. Signed-off-by: G. Manoj Kumar <[email protected]>
|
@fdncred thanks for the review! took the checked_rem change, so both early returns and their comments are gone. the roll tests now compare the actual value, and i added the table test with one empty row. left the roll up/down copy for a later pr like you said. roll tests pass locally (13). |
|
please replay to each review comment to ensure nothing is missed |
|
replied on each thread, sorry for marking them resolved without replying. i left the roll up / roll down copy alone like you said, happy to look at it in a separate pr if you want. roll tests pass locally. |
There was a problem hiding this comment.
Review overview
🟡 Changes recommended
The rotation now uses checked_rem in both the list and record paths, the early returns and their comments are gone, and the empty list and record tests compare values. The new table test can't fail, and one == ... true assert is left.
Findings: 0
Notes from my clanker, checked on 3f1c185. Read-only, branch not built; CI is green on all 11 checks. Record key order checked on nu 0.116.2: [{a: 1, b: 2} {}] == [{b: 2, a: 1} {}] is true. The roll up / roll down copy stays for a later PR, as agreed.
Record equality ignores key order, so compare the `to nuon` text to check the key order and that each value moved with its key, and drop the last `== ... true` assert. Signed-off-by: G. Manoj Kumar <[email protected]>
|
Thanks |



Description
rollpanics when the input is empty. On current main:I found these by running commands against empty and edge-case input. The cause is in
vertical_rotate_valueandhorizontal_rotate_value. Both don % len, which divides by zero when the list or record is empty. Without--by, the default rotation of 1 on an empty slice also asserts.The fix uses
checked_rem, so an empty list or record gets a rotation of 0 and is returned unchanged. I added tests forroll up,roll down,roll leftandroll righton empty input, one for empty records inside a list, and one for a table where only one row is empty.I ran the
rolltests locally and they pass (13). I haven't run the full test suite, so I'm relying on CI for that.User-facing changes (Release notes)
Fixed a panic when using
roll up,roll down,roll leftorroll righton an empty list or record.Additional notes
n/a