Fix null check in pattern matching for JSON.Array and JSON.Object#8252
Fix null check in pattern matching for JSON.Array and JSON.Object#8252jagguji wants to merge 8 commits intorescript-lang:masterfrom
Conversation
When pattern matching on JSON values with both Array and Object cases without an explicit Null case, the generated JavaScript incorrectly omitted the null check before Array.isArray(), causing runtime failures when the value is null. Root cause: typeof null === "object" in JavaScript, so the previous Object type check would incorrectly match null. Changes: 1. In is_not_block_case: Always add null check for ObjectType 2. In add_runtime_type_check: Always exclude null from Object case Fixes runtime error where null would incorrectly match Object case instead of falling through to the default/catch-all case. Signed-Off-By: Claude <noreply@anthropic.com>
|
Hello, thank you for your contribution! |
|
sure @nojaf will do it |
|
can u check now @nojaf |
|
Hi @cknitt, I'm less familiar with the build tests, does this look good to you? |
|
Please run Once CI reaches the |
|
hi @nojaf pkg-pr-new is skipped |
|
Well yes, because CI keeps failing: Did you ran this locally? |
|
intiailly i was not able to run it but now it's i ran it and it works fine, can u check now ? and approve this workflow ? |
rescript
@rescript/darwin-arm64
@rescript/darwin-x64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
|
@jagguji as mentioned above: Please try that out. |
|
|
||
| function classify$8(v) { | ||
| if (typeof v === "object" && !Array.isArray(v)) { | ||
| if (typeof v === "object" && v !== null && !Array.isArray(v)) { |
There was a problem hiding this comment.
This is a regression: null check not needed.
Btw the other test should also be of this form: a simple function in tests/tests/src so we can just look at the generated code, instead of an opaque case analysis with half a dozen cases
There was a problem hiding this comment.
@cristianoc The null check IS needed because of JavaScript's typeof null === "object".
hey i was trying it with yarn we were using the yarn 3.2.1, and it's not working |
|
hi @nojaf @cristianoc can u pls have a look at it again, and let me know if anything still open, i don't think u are understanding our situation our prod migration is delayed because of this can u pls fastrack this |
When pattern matching on JSON values with both Array and Object cases without an explicit Null case, the generated JavaScript incorrectly omitted the null check before Array.isArray(), causing runtime failures when the value is null.
Root cause: typeof null === "object" in JavaScript, so the previous Object type check would incorrectly match null.
Changes:
Fixes runtime error where null would incorrectly match Object case instead of falling through to the default/catch-all case.
#8251