Skip to content

Box Some of a constant case represented by undefined - #9008

Merged
cknitt merged 1 commit into
masterfrom
untagged-some-undefined-constant
Oct 24, 2026
Merged

cknitt merged 1 commit into
masterfrom
untagged-some-undefined-constant

Conversation

@cknitt

@cknitt cknitt commented Oct 24, 2026

Copy link
Copy Markdown
Member

Fixes #8954.

Some(U) with @as(undefined) U compiled to plain undefined when U was a constant, so it equalled None, while Some(v) with v = U at run time stayed distinct:

@unboxed type u = | @as(undefined) U | V(string)
let x: option<u> = Some(U)                       // let x = undefined;
@inline(never) let mk = (v: u): option<u> => Some(v)
Console.log2(x == None, mk(U) == None)           // true false

The cause was the one the spec conjectured: Lambda.const_some_none_depth treated every Const_constructor as "not a none", including one whose literal is undefined. Such a constructor is now a none, so Some of it is boxed like Some(None): let x = Primitive_option.some(undefined);, and the program prints false false. Tagged variants with an @as(undefined) case are fixed the same way.

UntaggedVariants.md: the known bug is removed, and rule 12 states the case.

New test: untagged_variants_spec_test.res rule 12 checks a constant Some(WUndefined).

🤖 Generated with Claude Code

https://claude.ai/code/session_01CMkrYaktctdKc4M41WF36t

Why:
    `Some(U)` with `@as(undefined) U` compiled to plain `undefined` when `U`
    was a constant, so it was `None`, while `Some(v)` with `v = U` passed at
    run time stayed distinct (#8954).

A constant constructor whose literal is `undefined` is now a none for
`const_some_none_depth`, so `Some` of it is boxed like `Some(None)`. This
holds for untagged and tagged variants alike. The spec's known bug is gone,
and rule 12 states the case.

JS modified:
Example:
    @unboxed type u = | @as(undefined) U | V(string)
    let x: option<u> = Some(U)
Before (js): let x = undefined;
After (js): let x = Primitive_option.some(undefined);

Fixes: #8954
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

  • 🐛 Keep Some(U) distinct from None when U is a constant case represented by undefined (@as(undefined)).

Semantic Diff

1 commit · Full page

Box Some of a constant case represented by undefined

b5836de · cknitt + Claude · Oct 24, 2026, 06:10 UTC

Why

Some(U) with @as(undefined) U compiled to plain undefined when U was a constant, so it was None, while Some(v) with v = U passed at run time stayed distinct (#8954).

A constant constructor whose literal is undefined is now a none for const_some_none_depth, so Some of it is boxed like Some(None). This holds for untagged and tagged variants alike. The spec's known bug is gone, and rule 12 states the case.

JS modified

@unboxed type u = | @as(undefined) U | V(string)
let x: option<u> = Some(U)

js

-let x = undefined;
+let x = Primitive_option.some(undefined);

@codecov

codecov Bot commented Oct 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 81.29%. Comparing base (d8db3c6) to head (b5836de).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
compiler/ml/lambda.ml 50.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9008   +/-   ##
=======================================
  Coverage   81.29%   81.29%           
=======================================
  Files         456      456           
  Lines       63836    63837    +1     
=======================================
+ Hits        51893    51894    +1     
  Misses      11943    11943           
Files with missing lines Coverage Δ
compiler/ml/lambda.ml 68.08% <50.00%> (+0.06%) ⬆️
🚀 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 24, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: b5836de

@cknitt

cknitt commented Oct 24, 2026

Copy link
Copy Markdown
Member Author

@codex review

@github-actions

Copy link
Copy Markdown

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 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-24T06:36:16.533676Z b5836de 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.

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

Copy link
Copy Markdown

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

Reviewed commit: b5836debf5

ℹ️ 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 24, 2026 06:44
@cknitt
cknitt merged commit 35b1e48 into master Oct 24, 2026
26 checks passed
@cknitt
cknitt deleted the untagged-some-undefined-constant branch October 24, 2026 08:42
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.

Some(U) of an @as(undefined) case compiles to undefined when U is a constant

2 participants