Skip to content

Reject unit arguments of @set, @set_index and @get_index externals - #9343

Merged
cknitt merged 2 commits into
masterfrom
set-unit-arg-error
Nov 20, 2026
Merged

cknitt merged 2 commits into
masterfrom
set-unit-arg-error

Conversation

@cknitt

@cknitt cknitt commented Nov 19, 2026

Copy link
Copy Markdown
Member

Fixes #9339.

A unit argument of an external is left out of the JS code. For @set, @set_index and @get_index that leaves the property access without its object, index or value, and the compiler crashed with Assertion failed. @get already rejected a unit argument.

Now all four reject it when the external is declared:

Ill defined attribute @set (unit argument is not allowed)

This covers a unit in any position, such as @set external setX: (unit, int) => unit.

An external like this that is declared but never called compiled before and is now an error. It could not be called without crashing, so I don't expect real code to have one.

Tests: new fixtures set_unit_arg.res, set_index_unit_arg.res and get_index_unit_arg.res in tests/build_tests/super_errors.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kbf3gHt1hL7PvCPo3r2viL

Why:
    A unit argument is left out of the JS code, so the compiler crashed
    with an assertion failure when it built the property access without
    its object, index or value (#9339). @get already rejected it.

Diagnostic added (unit argument of a property external):
Example:
    type t
    @set external setX: (t, unit) => unit = "x"
Before (diagnostic):
    Fatal error: exception File "compiler/core/lam_compile_external_call.ml", line 448, characters 11-17: Assertion failed
After (diagnostic):
    Ill defined attribute @set (unit argument is not allowed)

Review: Can such an external be useful? No. It would set or read a property with a part missing. Declaring one now fails even when it is never called; before, only a call crashed.

Fixes #9339

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

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Changelog

🐛 Bug fix

  • @set, @set_index and @get_index externals with a unit argument are now rejected with an error instead of crashing the compiler.

Semantic Diff

2 commits · Full page

Reject unit arguments of @set, @set_index and @get_index externals

1ce26e0 · cknitt + Claude · Nov 19, 2026, 19:12 UTC

Why

A unit argument is left out of the JS code, so the compiler crashed with an assertion failure when it built the property access without its object, index or value (#9339). @get already rejected it.

Diagnostic added (unit argument of a property external)

type t
@set external setX: (t, unit) => unit = "x"

diagnostic

-Fatal error: exception File "compiler/core/lam_compile_external_call.ml", line 448, characters 11-17: Assertion failed
+Ill defined attribute @set (unit argument is not allowed)

Fixes #9339

Review

  • Can such an external be useful? No. It would set or read a property with a part missing. Declaring one now fails even when it is never called; before, only a call crashed.
✨ Accept property externals whose arguments are all constants

8bdca68 · cknitt + Claude · Nov 19, 2026, 19:27 UTC · new

Why

When every argument is an @as constant, a unit parameter is added after the arguments so the external stays callable. The new unit check also saw that parameter, so it rejected valid externals such as @get external readX: @as(json{"x":1}) _ => int = "x". The checks now look at the declared arguments only.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

✅ Compiler benchmarks

Allocated words

In total: 639,845,235 → 639,843,825 (±0.00%).

Generated projects: 629,807,957 → 629,806,518 (±0.00%).

None of the 265 benchmarks changed by 0.1% or more.

Instructions

In total: 9,210,476,312 → 9,210,476,023 (±0.00%).

None of the 33 benchmarks changed by 0.1% or more.

Output size

In total: 25,919,386 → 25,919,534 (±0.00%).

None of the 13 benchmarks changed by 0.1% or more.

Pull request 8bdca68 compared with base 91d74a0 in this run.

@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.15%. Comparing base (91d74a0) to head (8bdca68).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9343      +/-   ##
==========================================
- Coverage   82.15%   82.15%   -0.01%     
==========================================
  Files         456      456              
  Lines       65658    65664       +6     
==========================================
+ Hits        53942    53946       +4     
- Misses      11716    11718       +2     
Files with missing lines Coverage Δ
compiler/frontend/ast_external_process.ml 77.96% <100.00%> (+0.44%) ⬆️

... and 1 file with indirect coverage changes

🚀 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.

@cknitt

cknitt commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

@codex review

@cknitt
cknitt marked this pull request as ready for review November 19, 2026 19:24
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T19:30:27.565387Z 8bdca68 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 chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1ce26e02f4

ℹ️ 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".

Why:
    When every argument is an @as constant, a unit parameter is added
    after the arguments so the external stays callable. The new unit
    check also saw that parameter, so it rejected valid externals such as
    @get external readX: @as(json`{"x":1}`) _ => int = "x". The checks now
    look at the declared arguments only.

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

cknitt commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 8bdca68e6a

ℹ️ 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".

@pkg-pr-new

pkg-pr-new Bot commented Nov 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 8bdca68

@github-actions

Copy link
Copy Markdown

@cknitt
cknitt merged commit 10ec938 into master Nov 20, 2026
22 checks passed
@cknitt
cknitt deleted the set-unit-arg-error branch November 20, 2026 13:10
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 @set or @set_index external with a unit value crashes the compiler

2 participants