Skip to content

Stop warning 20 on calls of open JS object methods - #8921

Draft
cknitt wants to merge 4 commits into
masterfrom
js-object-method-unused-arg-warning
Draft

cknitt wants to merge 4 commits into
masterfrom
js-object-method-unused-arg-warning

Conversation

@cknitt

@cknitt cknitt commented Oct 19, 2026

Copy link
Copy Markdown
Member

Calling a method of an open JS object type, e.g. cd(e)["getData"]("text/plain") with cd: string => {..}, reported warning 20 "this argument will not be used by the function". The method's type is a fresh type variable, which the warning reads as "the function never returns", but the JS method does receive the argument. The warning is now skipped when the applied expression is an object property read (Texp_object_get); other fresh-variable cases such as failwith("x")(1) still warn.

Fixes #8159.

New super_errors fixture unused_argument_object_method.res covers both the object method call (no warning) and the failwith case (warning kept).

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo

Calling a method read from an open JS object type, such as
`obj["getData"]("text/plain")` with `obj: {..}`, no longer reports warning
20 "this argument will not be used by the function". The method's type is a
fresh type variable, which the warning took as a sign that the function
never returns, but the call passes its arguments to the JS method. Calls
whose function is a fresh type variable for other reasons, such as
`failwith("x")(1)`, still warn.

Example (rescript):
    @get external clipboardData: string => {..} = "clipboardData"
    let text = clipboardData("event")["getData"]("text/plain")

Diagnostic (text):
    Before: Warning number 20 on "text/plain":
      this argument will not be used by the function.
    After: no warning.

Area: typechecker tests
Output: unchanged
Formatting: unchanged
Formats: none
PPX: unchanged
Editor: unchanged
Tests: +tests/build_tests/super_errors/fixtures/unused_argument_object_method.res +tests/build_tests/super_errors/expected/unused_argument_object_method.res.expected
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo
Signed-off-by: Christoph Knittel <ck@cca.io>
@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.14%. Comparing base (58da277) to head (67cea1e).
⚠️ Report is 10 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8921      +/-   ##
==========================================
+ Coverage   81.03%   81.14%   +0.10%     
==========================================
  Files         455      456       +1     
  Lines       63640    63758     +118     
==========================================
+ Hits        51573    51735     +162     
+ Misses      12067    12023      -44     
Files with missing lines Coverage Δ
compiler/ml/typecore.ml 86.81% <100.00%> (+0.22%) ⬆️

... and 34 files 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.

@pkg-pr-new

pkg-pr-new Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 67cea1e

@github-actions

Copy link
Copy Markdown

@cknitt

cknitt commented Oct 20, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 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-20T13:53:17.099987Z 67cea1e 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: a085ae910f

ℹ️ 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/typecore.ml
cknitt and others added 2 commits October 20, 2026 13:31
Calling an object field still reports warning 20 "this argument will not be
used by the function" unless the read added the field to an open object row.
The exemption for open JS object methods covered every object field read, so
calls of fields that cannot return, such as `failwith("boom")["m"](x)` or
`{"m": failwith("boom")}["m"](x)`, lost the warning. The read now records the
fresh variable it creates for a field added to an open row, and the
application skips the warning only when its callee is that variable.

Example (rescript):
    @get external clipboardData: string => {..} = "clipboardData"
    let text = clipboardData("event")["getData"]("text/plain")
    let fromFailwith = () => failwith("boom")["m"](Console.log("b"))

Diagnostic (text):
    Before: no warning on either call.
    After: warning 20 on Console.log("b") only, as on master.

Review: Why a global slot rather than a typed-tree flag? The callee's read is
 the last read typed before its application, and the slot is set on every
 read and compared by physical equality with the callee's type, so it only
 matches the callee's own read. A typed-tree field would change Texp_object_get
 and the .cmt format for a warning.

Area: typechecker tests
Output: unchanged
Formatting: unchanged
Formats: none
PPX: unchanged
Editor: unchanged
Tests: ~tests/build_tests/super_errors/fixtures/unused_argument_object_method.res ~tests/build_tests/super_errors/expected/unused_argument_object_method.res.expected
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo
Signed-off-by: Christoph Knittel <ck@cca.io>
Arguments that read object fields, from closed or open objects, in first or
last position or through a nested method call, keep the call of an open JS
object method free of warning 20. The exemption is decided before any
argument is typed, so their reads cannot replace the callee's.

Example (rescript):
    let closedFirst = clipboardData("e")["m"](closed["x"], "a")
    let nested = clipboardData("e")["m"](clipboardData("f")["n"]("y"))

Diagnostic (text):
    no warning, before and after this commit.

Area: tests
Output: unchanged
Tests: ~tests/build_tests/super_errors/fixtures/unused_argument_object_method.res ~tests/build_tests/super_errors/expected/unused_argument_object_method.res.expected
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt

cknitt commented Oct 20, 2026

Copy link
Copy Markdown
Member Author

@codex review

@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: 0b9449a508

ℹ️ 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/typecore.ml
The fixture for warning 20 on object methods writes its never-returning
expressions as `throw(Failure(...))` instead of the deprecated `failwith`, so
its expected output holds only warning 20 once `failwith` reports warning 3.
It also covers an open object that is kept in a binding and whose method is
read before it is called: that call reports no warning 20 either.

Example (rescript):
    let retained = clipboardData("e")
    let first = retained["m"]
    let second = retained["m"]("used")

Diagnostic (text):
    no warning on `"used"`.

Review: Does the retained case need a record of every open-row field
 variable? No: a binding keeps the object type at the binding's level, below
 the level of the later call, so the call's fresh-variable check does not
 apply and no warning is reported.

Area: tests
Output: unchanged
Tests: ~tests/build_tests/super_errors/fixtures/unused_argument_object_method.res ~tests/build_tests/super_errors/expected/unused_argument_object_method.res.expected
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo
Signed-off-by: Christoph Knittel <ck@cca.io>
@github-actions

Copy link
Copy Markdown

@cknitt

cknitt commented Oct 20, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 67cea1ed83

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

This branch has not been deployed

No deployments
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.

Misleading this argument will not be used by the function warning

1 participant