Skip to content

Fix partial application generalization for ...#8343

Open
cknitt wants to merge 1 commit intomasterfrom
alpha.4
Open

Fix partial application generalization for ...#8343
cknitt wants to merge 1 commit intomasterfrom
alpha.4

Conversation

@cknitt
Copy link
Copy Markdown
Member

@cknitt cknitt commented Apr 12, 2026

Fix partial application generalization for ...

Summary

Fixes #8334.

ReScript treated foo(arg, ...) differently from foo(arg, _) during
generalization:

  • foo(arg, _) was parsed into an explicit lambda, so it was treated as a
    function value and could be generalized.
  • foo(arg, ...) stayed as a partial application node in the typed tree, so it
    was treated as expansive and could end up with weak type variables.

That caused code like this to fail:

type hook

external hook: hook = "hook"
external addHook: (hook, 'a => unit) => unit = "addHook"

let addHookPartial = addHook(hook, ...)

with:

This expression's type contains type variables that cannot be generalized:
('_weak1 => unit) => unit

Fix

Treat ReScript partial applications with partial = true as nonexpansive in
the value restriction check.

This matches the runtime/codegen behavior: foo(arg, ...) is ultimately lowered
to a wrapper function, so it should be classified like an explicit lambda for
generalization purposes.

Tests

Added a regression to tests/tests/src/PartialApplicationNoRuntimeCurry.res
covering the reported polymorphic callback case:

  • create addHookPartial = addHook(hook, ...)
  • use it at int
  • use it again at string

Updated the expected generated output in the matching .mjs fixture.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 12, 2026

Open in StackBlitz

rescript

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

@rescript/darwin-arm64

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

@rescript/darwin-x64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 55f684a

@cknitt cknitt requested a review from cristianoc April 12, 2026 07:51
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.

Error when using ... and not _

2 participants