Repository navigation
Propagate errors from recursive calls in sort - #4767
Open
diracdeltafunk wants to merge 1 commit into
Open
diracdeltafunk wants to merge 1 commit into
diracdeltafunk wants to merge 1 commit into
Conversation
subsort returned errors from the comparisons it made itself but ignored the values of its recursive calls, so an error from a ? method was dropped whenever it happened below the top level, and sort and rsort returned a partially sorted list instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 of 12 tasks
diracdeltafunk
marked this pull request as ready for review
October 31, 2026 00:04
5 of 12 tasks
Member
|
Just a thought: wouldn't it be better if sort didn't fail on incomparable elements, but just ordered the elements by the partial order? (Ideally with the order of incomparable elements matching their original order) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
sortandrsortdrop an error raised by a?method whenever the failing comparison happens inside one of quicksort's recursive calls.subsort(ind/actors3.d) returns the error from each comparison it makes itself, but ignores the values returned by its recursive calls, so the caller gets a partially sorted list and no error. This change returns those errors too.basicsortalready restores its saved state whensubsortreturns an error, so nothing else is needed.Before:
{T{2}, T{1}, T{0}, T{3}, T{4}}, with no error.After:
error: incomparable.Testing
Added a case to
tests/normal/sort.m2: a?method that fails on one pair of adjacent elements. Quicksort compares adjacent elements at some level of the recursion whatever pivots it picks, so the test doesn't depend on pivot choice. Both new assertions fail on 1.26.06 and pass with this change.Built on macOS (arm64, CMake) and ran
tests/normal, with no new failures.Release notes
sortandrsortno longer ignore errors raised by the comparison method.AI disclosure
Tools and models used: Claude Code (Claude Opus 5.5). The bug was first flagged in an automated audit by Codex.
How AI was used, and on which parts: Claude reproduced the bug, wrote the fix, the test, and this description.
How I verified the result: I read the code and looked at test outputs.
License
Checklist
developmentbranch.🤖 Generated with Claude Code