Repository navigation
records: keep {{ }} fields in the order written - #261
Merged
Merged
Conversation
An object literal's fields are inferred in dependency order, and its record
type listed them in that order: {{b: a + 1, a: 1}} had fields a, b. Order
the type's fields as written instead, so whatever iterates them (sortBy's
record keys, JSON.encode's declaration order) sees the fields as the reader
does.
Signed-off-by: Alex Suraci <[email protected]>
Deploying dang with
|
| Latest commit: |
d9159da
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://59875962.dang-3kk.pages.dev |
| Branch Preview URL: | https://record-literal-order.dang-3kk.pages.dev |
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.
Record literals used to store their fields in dependency order: inference visits fields so that each one comes after the siblings it references, and the record type's fields kept that order.
{{b: a + 1, a: 1}}had fieldsa, b. With this change the type keeps the order the fields are written in (b, a). Inference order is unchanged.Two open PRs depend on this:
sortByrecord keys compare field by field in written order.JSON.encodewrites fields in declaration order.Release notes: this is a behavior change, but you can only see it through key order: iterating a record's fields, and the encoders once #255 lands. Equality, field access and type display are unaffected.
Test:
TestRecordLiteralKeepsWrittenFieldOrder(pkg/dang/record_order_test.go).