Preserve element type through sort/sort_natural filters - #1298
Open
Aryaneefds wants to merge 1 commit into
Open
Conversation
Fixes Shopify#1086: media | sort lost its type (untyped[]) because the docset declares sort as returning an untyped array. Infer the input type instead: arrays keep their value type, single values wrap into a single-element array type, unknown input falls back to docset.
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.
Fixes #1086.
Problem:
media | sort(the single-object-to-array trick) andimages | sortboth inferred asuntyped[]because the docset declaressortas returning an untyped array — the element type was lost.Fix (
TypeSystem.ts,LiquidVariableinference): when the last filter issort/sort_natural, infer the input type instead of using the docset return type —product[] | sort→product[])media | sort→media[]), chain-safe via recursion without the last filteruntyped/unknowninput falls back to the docset type (no behavior change there)Tests: 6 new cases in
TypeSystem.spec.ts(array preserve, single-value wrap,sort_natural, chained sorts, lookup-type preserve, unknown fallback). Suite: 35 passed, 1 skipped (pre-existing skip).