Skip to content

added inline sorted by expression support with InputSource and as…#8436

Open
ethanrjs wants to merge 5 commits intoSkriptLang:dev/featurefrom
ethanrjs:feature/expr-sorted-by
Open

added inline sorted by expression support with InputSource and as…#8436
ethanrjs wants to merge 5 commits intoSkriptLang:dev/featurefrom
ethanrjs:feature/expr-sorted-by

Conversation

@ethanrjs
Copy link

@ethanrjs ethanrjs commented Feb 9, 2026

Problem

ExprSortedList only supports basic natural-order sorting via sorted %objects%. To sort with a custom comparator or in descending order, you have to use EffSort, which mutates in-place, meaning you're forced to copy the list first:

copy {-myStoredObjects::*} into {_temp::*}
sort {_temp::*} in descending order by (name of input)
return {_temp::*}

Solution

Added sorted ... by expression patterns to ExprSortedList with InputSource support, matching EffSort's behavior. The existing sorted %objects% pattern is unchanged.

return {-myStoredObjects::*} sorted in descending order by (name of input)

Testing Completed

Added ExprSortedList.sk test file covering basic sorting, ascending/descending with sort-by, and edge cases.
image

Also ran tests on-server.
image

Supporting Information

First contribution. Open to feedback :).


Completes: #8366
Related: #6158
AI assistance: Opus 4.6 Max reviewed my code + wrote tests in ExprSortedList.sk

…cending/descending order to ExprSortedList.
@ethanrjs ethanrjs requested a review from a team as a code owner February 9, 2026 17:32
@ethanrjs ethanrjs requested review from Absolutionism and Burbulinis and removed request for a team February 9, 2026 17:32
Copy link
Member

@sovdeeth sovdeeth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks pretty good so far!

…ReturnType() instead of Object.class fixing a ClassCastException
Copy link
Member

@sovdeeth sovdeeth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

almost there!

Comment on lines +193 to +194
catch runtime errors:
assert ({_data::*} sorted by ("%input%" parsed as time)) is not set with "keyed null mapping returned a value"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should also assert the runtime error is what you expect it to be

Comment on lines 226 to 242
# 'health of' requires %living entities%; 'all entities' returns %entities%,
# forcing getConvertedExpression(LivingEntity.class) on the sorted-by expression.
delete all entities in radius 50 around test-location
spawn a zombie at test-location:
set {_z1} to entity
set entity's name to "charlie"
spawn a zombie at test-location:
set {_z} to entity
spawn a pig at test-location:
set {_p} to entity
set {_entities::*} to {_z} and {_p}
set {_healths::*} to health of ({_entities::*} sorted by (health of input))
assert size of {_healths::*} is 2 with "sorted-by entity type conversion: wrong count"
assert first element of {_healths::*} <= last element of {_healths::*} with "sorted-by entity type conversion: not ascending"
delete entity within {_z}
delete entity within {_p}
set {_z2} to entity
set entity's name to "alpha"
spawn a zombie at test-location:
set {_z3} to entity
set entity's name to "bravo"

set {_names::*} to names of ((all entities in radius 2 around test-location) sorted by (input's name))
assert {_names::*} is "alpha", "bravo" and "charlie" with "sorted-by input name failed"
set {_healths::*} to health of ((all entities in radius 2 around test-location) sorted by (input's name))
assert size of {_healths::*} is 3 with "sorted-by entity conversion failed"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is still a good test, but I would also add one that does inventories within ()
Bonus points for having a non-inventory holding entity like a minecart, and asserting that it's removed from the end list.

@github-project-automation github-project-automation bot moved this to In Review in 2.15 Releases Feb 10, 2026
@sovdeeth sovdeeth added the feature Pull request adding a new feature. label Feb 10, 2026
@sovdeeth sovdeeth linked an issue Feb 10, 2026 that may be closed by this pull request
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Pull request adding a new feature.

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

Add an in-line sort by expression

3 participants