Skip to content

Fix null falling into object branch in untagged variant switch#8253

Merged
cristianoc merged 1 commit intomasterfrom
fix-null-typeof-object-8251
Feb 25, 2026
Merged

Fix null falling into object branch in untagged variant switch#8253
cristianoc merged 1 commit intomasterfrom
fix-null-typeof-object-8251

Conversation

@cristianoc
Copy link
Collaborator

Summary

  • Fix null (which has typeof "object") incorrectly falling into the Object branch instead of the wildcard when pattern matching on untagged variants that have both an Object case and a null/wildcard case.
  • Emit a null check before the typeof switch when both conditions are present.

Fixes #8251

Test plan

  • Added test in js_json_test.res that exercises Array, Object, and wildcard matching with null input
  • make test passes

🤖 Generated with Claude Code

When pattern matching on untagged variants with both an Object case and
a null/wildcard case, null (typeof "object") would incorrectly match
the object branch. Emit a null check before the typeof switch when both
conditions are present.

Fixes #8251

Signed-Off-By: Cristiano Calcagno <cristiano.calcagno@gmail.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 25, 2026

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@8253

@rescript/darwin-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-arm64@8253

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@8253

@rescript/linux-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-arm64@8253

@rescript/linux-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-x64@8253

@rescript/runtime

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/runtime@8253

@rescript/win32-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/win32-x64@8253

commit: 61b6f10

Copy link
Member

@nojaf nojaf left a comment

Choose a reason for hiding this comment

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

Thanks!

@cristianoc cristianoc merged commit ebed19a into master Feb 25, 2026
49 of 51 checks passed
@cristianoc cristianoc deleted the fix-null-typeof-object-8251 branch February 25, 2026 09:05
@jagguji
Copy link

jagguji commented Feb 25, 2026

how can i use this @nojaf via the
yarn https://pkg.pr.new/rescript-lang/rescript@8253
itself ?

Also can u confirm it this handles these cases as well, sometimes the array was also falling into the object case @cristianoc
switch jsonNull { | Object() => "Object" | Array() => "Array" | _ => "default" }
switch jsonNull { | Object() => "Object" | String() => "String" | _ => "default" }
switch jsonNull { | Object() => "Object" | Number() => "Number" | _ => "default" }
switch jsonNull->JSON.Classify.classify { | Object() => "Object" | Bool() => "Boolean" | _ => "default" }
switch jsonNull { | Object() => "Object" | Array() => "Array" | String() => "String" | _ => "default" }
switch jsonArray { | Object() => "Object" | String() => "String" | _ => "default" }
switch jsonArray { | Object() => "Object" | Number() => "Number" | _ => "default" }
switch jsonArray { | Object() => "Object" | Bool(_) => "Boolean" | _ => "default" }

@nojaf
Copy link
Member

nojaf commented Feb 25, 2026

how can i use this @nojaf via the
yarn https://pkg.pr.new/rescript-lang/rescript@8253
itself ?

I'm not sure what your expectations are this does.
But try replace you current rescript version with https://pkg.pr.new/rescript-lang/rescript@8253 in package.json.
Same for @rescript/runtime if you use it directly: https://pkg.pr.new/rescript-lang/rescript/@rescript/runtime@8253

then I would expect yarn to pick it up.

Maybe yarn dlx https://pkg.pr.new/rescript-lang/rescript@8253 but I don't really use yarn myself much. It is used in this repo but was set up by others who are more familiar with all of this.

@jagguji
Copy link

jagguji commented Feb 25, 2026

yeah i want to point to this version only @nojaf
will try the above steps

Also do u know when we can expect this fix in upcoming release ?

@jagguji
Copy link

jagguji commented Feb 25, 2026

i can't use it actually as it's using the rescript "version": "13.0.0-alpha.2", which can cause other issue, are we planning to release thsi as path in rescript 12 only
thanks @nojaf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generated JS missing null check when pattern matching JSON.Array and JSON.Object

3 participants