Fix Bool deserialized as number in TS SDK fast path#4596
Open
clockwork-labs-bot wants to merge 1 commit intomasterfrom
Open
Fix Bool deserialized as number in TS SDK fast path#4596clockwork-labs-bot wants to merge 1 commit intomasterfrom
clockwork-labs-bot wants to merge 1 commit intomasterfrom
Conversation
The isFixedSizeProduct fast-path deserializer used view.getUint8()
for Bool fields, which returns a number (0 or 1) instead of a
boolean. The slow path (reader.readBool()) correctly uses !== 0.
Fix: special-case Bool in the fast path to emit:
result.foo = view.getUint8(reader.offset) !== 0;
instead of:
result.foo = view.getUint8(reader.offset);
This caused useTable to return {foo: 1} instead of {foo: true}
for products containing only fixed-size primitives.
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 #4591
Root Cause
The
isFixedSizeProductfast-path deserializer inalgebraic_type.tsmapsBooltoview.getUint8(), which returns a number (0 or 1) instead of a JavaScript boolean. The slow path (reader.readBool()) correctly converts via!== 0.This means any product type containing only fixed-size primitives (bools, ints, floats) hits the fast path and returns numbers for boolean fields. Products containing strings, arrays, or nested objects go through the slow path and work correctly.
This explains the inconsistency in the issue: a flat
{ foo: bool }returns{ foo: 1 }, but adding a nested object pushes it to the slow path wherefoobecomestrue(though the nested bool still hits the fast path within its own product).Fix
Special-case
Boolin the fast-path code generation to emit:instead of:
One-line change in the ternary within
makeDeserializer.