Skip to content

Fix a bool payload beside a bool literal in an incomplete match - #9036

Merged
cknitt merged 1 commit into
masterfrom
fix-bool-payload-simplify
Oct 25, 2026
Merged

cknitt merged 1 commit into
masterfrom
fix-bool-payload-simplify

Conversation

@cknitt

@cknitt cknitt commented Oct 25, 2026

Copy link
Copy Markdown
Member

Fixes #9035.

Js_exp_make.simplify_and_ rewrote typeof x === "boolean" && x !== b to the constant !b. Its doc comment says the result is x === !b, which is the correct one. A match on a bool payload of an untagged variant, beside a bool literal case, produces exactly this conjunction. So in a match that doesn't name every case, the payload arm was never taken (@as(true)) or always taken (@as(false)).

New test: untagged_bool_payload_test.res covers a bool payload beside @as(true) and beside @as(false), with values that aren't folded at compile time.

Found by a review of the untagged variant work (#8950).

🤖 Generated with Claude Code

https://claude.ai/code/session_01CMkrYaktctdKc4M41WF36t

Why:
    `typeof x === "boolean" && x !== b` was simplified to the constant `!b`,
    not to `x === !b` as its doc comment says. A match on a bool payload
    beside a bool literal case produces this conjunction, so it never or
    always took the payload arm (#9035).

JS modified (bool payload beside a bool literal):
Example:
    @unboxed type t = | @as(true) LitTrue | AnyBool(bool) | AnyInt(int)
    let f = (v: t) =>
      switch v {
      | AnyBool(_) => "bool"
      | _ => "other"
      }
Before (js):
    function f(v) {
      return "other";
    }
After (js):
    function f(v) {
      if (v !== false) {
        return "other";
      } else {
        return "bool";
      }
    }

Fixes #9035

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CMkrYaktctdKc4M41WF36t
Signed-off-by: Christoph Knittel <ck@cca.io>
@github-actions

Copy link
Copy Markdown

Changelog

🐛 Bug fix

  • Fix matching a bool payload of an untagged variant beside a bool literal case in a match that does not name every case.

Semantic Diff

1 commit · Full page

Simplify a boolean other than one to the other boolean

717d266 · cknitt + Claude · Oct 25, 2026, 06:02 UTC

Why

typeof x === "boolean" && x !== b was simplified to the constant !b, not to x === !b as its doc comment says. A match on a bool payload beside a bool literal case produces this conjunction, so it never or always took the payload arm (#9035).

JS modified (bool payload beside a bool literal)

@unboxed type t = | @as(true) LitTrue | AnyBool(bool) | AnyInt(int)
let f = (v: t) =>
  switch v {
  | AnyBool(_) => "bool"
  | _ => "other"
  }

js

 function f(v) {
-  return "other";
+  if (v !== false) {
+    return "other";
+  } else {
+    return "bool";
+  }
 }

Fixes #9035

@cknitt

cknitt commented Oct 25, 2026

Copy link
Copy Markdown
Member Author

@codex review

@cknitt
cknitt marked this pull request as ready for review October 25, 2026 06:04
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-25T06:18:21.344248Z 717d266 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 717d266fa3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@codecov

codecov Bot commented Oct 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.33%. Comparing base (d48d577) to head (717d266).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9036   +/-   ##
=======================================
  Coverage   81.32%   81.33%           
=======================================
  Files         456      456           
  Lines       64042    64042           
=======================================
+ Hits        52082    52086    +4     
+ Misses      11960    11956    -4     
Files with missing lines Coverage Δ
compiler/core/js_exp_make.ml 69.03% <100.00%> (+0.56%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new

pkg-pr-new Bot commented Oct 25, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@9036

@rescript/belt

npm i https://pkg.pr.new/@rescript/belt@9036

@rescript/darwin-arm64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@9036

@rescript/win32-x64

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

commit: 717d266

@cknitt

cknitt commented Oct 25, 2026

Copy link
Copy Markdown
Member Author

@codex review

@github-actions

Copy link
Copy Markdown

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 717d266fa3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cknitt
cknitt requested a review from cristianoc October 25, 2026 06:25

@cristianoc cristianoc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Noticing the pr description is low quality.
While the commit description is medium quality.

We should look into improving the text of PR descriptions.

@cknitt
cknitt merged commit 096af6d into master Oct 25, 2026
26 checks passed
@cknitt
cknitt deleted the fix-bool-payload-simplify branch October 25, 2026 06:39
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.

A bool payload beside a bool literal never matches in an incomplete match

2 participants