Skip to content

Enforce function arity in type inclusion and coercion - #8559

Open
cristianoc wants to merge 1 commit into
masterfrom
codex/function-arity-inclusion
Open

Enforce function arity in type inclusion and coercion#8559
cristianoc wants to merge 1 commit into
masterfrom
codex/function-arity-inclusion

Conversation

@cristianoc

Copy link
Copy Markdown
Collaborator

Summary

  • enforce function arity when checking value inclusion, type equality, and coercions
  • report the corresponding arity mismatch through aliases and nested function types
  • add regression coverage for both inclusion directions, aliases, nested functions, manifest type equality, and coercions

Why

A curried implementation such as int => int => int could previously satisfy an uncurried interface such as (int, int) => int, or be coerced to that type. Calls through the declared interface are emitted as plain JavaScript calls with the declared arity, so first-class uses could return a closure where a value was expected.

The root cause was that unification checked arrow arity, while the parallel moregen, eqtype, and subtype_rec paths did not.

Validation

  • make test
  • node tests/build_tests/super_errors/input.js
  • node tests/build_tests/super_errors_multi/input.js
  • make checkformat

@cristianoc
cristianoc force-pushed the codex/function-arity-inclusion branch from faecc7b to 88d1209 Compare August 18, 2026 07:37
Add the arity guard (already present in unify) to the Tarrow cases of
moregen, eqtype, and subtype_rec. Previously a curried implementation
(int => int => int) could satisfy an uncurried interface
((int, int) => int) through signature inclusion or :> coercion; calls
made through the interface type compile to direct JavaScript calls with
the declared arity, so a first-class use of such a value miscompiled
(e.g. returning a closure where an int was expected).

The value-mismatch report in includemod now prints a dedicated hint
when the two sides are functions of different arities, replacing the
vestigial empty curry_kind slot.

mcomp is deliberately left arity-lenient: it is an incompatibility
oracle for pattern and GADT reasoning, where leniency errs toward
"possibly compatible".

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.54%. Comparing base (0e5d0f0) to head (1e014c4).

Files with missing lines Patch % Lines
compiler/ml/includemod.ml 87.50% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #8559   +/-   ##
=======================================
  Coverage   75.54%   75.54%           
=======================================
  Files         476      476           
  Lines       62710    62732   +22     
=======================================
+ Hits        47374    47393   +19     
- Misses      15336    15339    +3     
Files with missing lines Coverage Δ
compiler/ml/ctype.ml 59.06% <100.00%> (ø)
compiler/ml/includemod.ml 74.58% <87.50%> (+0.93%) ⬆️
🚀 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 Aug 18, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/darwin-arm64

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

@rescript/darwin-x64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 1e014c4

@github-actions

Copy link
Copy Markdown

@cristianoc
cristianoc marked this pull request as ready for review August 18, 2026 13:01
@cristianoc
cristianoc requested a review from cknitt August 18, 2026 13:02

@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: 1e014c4432

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

Comment thread compiler/ml/includemod.ml
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.

1 participant