Skip to content

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

Draft
cknitt wants to merge 1 commit into
masterfrom
js-object-method-unused-arg-warning
Draft

cknitt wants to merge 1 commit 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. clipboardData(e)["getData"]("text/plain") with clipboardData: string => {..}, reported warning 20 "this argument will not be used by the function". The read adds the method to the open row with a fresh type variable as its type. The warning took that variable to mean "this function never returns", but the JS method does receive its arguments.

A field read that adds a field to an open row now records that field's type. The application skips the warning only when its callee is that read. Callees that cannot return still warn, including field reads on them: throw(e)(1), throw(e)["m"](x), {"m": throw(e)}["m"](x). The record is request-local, so requests type-checked at the same time on other domains cannot overwrite it.

Fixes #8159.

New tests:

  • super_errors fixture unused_argument_object_method.res: open object method calls (also with field reads in the arguments, nested calls, and a method read before the call) report nothing. The never-returning cases above keep warning 20.
  • ounit concurrent_open_object_method: two concurrent requests compile open object method calls with -w +20 and expect no warning.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kbf3gJavp7rWUAfzV9rjFj

@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.68%. Comparing base (f88294f) to head (86453bb).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8921      +/-   ##
==========================================
+ Coverage   81.67%   81.68%   +0.01%     
==========================================
  Files         455      455              
  Lines       64859    64891      +32     
==========================================
+ Hits        52974    53009      +35     
+ Misses      11885    11882       -3     
Files with missing lines Coverage Δ
compiler/ml/typecore.ml 89.27% <100.00%> (+0.05%) ⬆️
tests/ounit_tests/ounit_compiler_request_tests.ml 97.15% <100.00%> (+0.05%) ⬆️

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

@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: 86453bb

@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-21T11:00:19.349027Z 8f403db 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 Resolved
@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 Resolved
@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".

@cknitt

cknitt commented Oct 21, 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: cc2b5c9ccf

ℹ️ 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 Resolved
Comment thread compiler/ml/typecore.ml Resolved
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Changelog

🐛 Bug fix

  • Fix warning 20 ("this argument will not be used by the function") firing on calls of methods of open JS object types, such as obj["getData"]("text/plain").

Semantic Diff

1 commit · Full page

✏️ Stop warning 20 on calls of open JS object methods

86453bb · cknitt + Claude · Nov 01, 2026, 16:59 UTC · edited

Why

Calling a method read from an open JS object type, such as obj["getData"]("text/plain") with obj: {..}, reported warning 20 "this argument will not be used by the function". The read adds the method to the object's open row with a fresh type variable as its type, and type_application takes a callee whose type is a fresh variable as a function that never returns. The JS method does receive its arguments. Fixes #8159.

The read of a field that the open row gains now records that field's type, and the application skips the warning only when its callee is that read. Callees that cannot return still warn, including field reads on them: throw(e)(1), throw(e)["m"](x), {"m": throw(e)}["m"](x).

Diagnostic removed (warning 20 on open object methods)

@get external clipboardData: string => {..} = "clipboardData"
let text = clipboardData("event")["getData"]("text/plain")
let fromThrow = () => throw(Failure("boom"))["m"](Console.log("b"))

diagnostic

 Warning number 20
-Ex.res:2:46-57
-this argument will not be used by the function.
-
-Warning number 20
 Ex.res:3:51-66
 this argument will not be used by the function.

Review

  • Why does the read record the field type instead of the typed tree marking the callee? The Pexp_apply case clears the record, types the callee and reads the record right away, comparing it with the callee's type by physical equality, so only the callee's own read can match. It passes the result to type_application as ~open_row_method. A typed-tree flag would change Texp_object_get and the .cmt format for a warning.
  • Can a read inside an argument replace the callee's record? No: the check runs before any argument is typed. The fixture covers arguments that read closed and open object fields, first or last, and nested method calls.
  • Why a Request_local key rather than a plain ref? Requests type-checked concurrently on separate domains would share a ref, and one could overwrite another's record between typing a callee and checking it. An ounit test compiles open-object method calls in two concurrent requests with warning 20 on and expects none; it failed on every run with a shared ref.
  • Does a method read before the call, let o = f("e") then o["m"] and o["m"]("used"), need a record of every field? No: the binding keeps the object type at the binding's level, below the level of the later call, so the fresh-variable check does not apply.

@cknitt

cknitt commented Oct 21, 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: 8f403db920

ℹ️ 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 force-pushed the js-object-method-unused-arg-warning branch 2 times, most recently from 5e83724 to afec64d Compare October 30, 2026 09:00
Why:
    Calling a method read from an open JS object type, such as
    `obj["getData"]("text/plain")` with `obj: {..}`, reported warning 20
    "this argument will not be used by the function". The read adds the
    method to the object's open row with a fresh type variable as its
    type, and type_application takes a callee whose type is a fresh
    variable as a function that never returns. The JS method does receive
    its arguments. Fixes #8159.

    The read of a field that the open row gains now records that field's
    type, and the application skips the warning only when its callee is
    that read. Callees that cannot return still warn, including field reads
    on them: `throw(e)(1)`, `throw(e)["m"](x)`, `{"m": throw(e)}["m"](x)`.

Diagnostic removed (warning 20 on open object methods):
Example:
    @get external clipboardData: string => {..} = "clipboardData"
    let text = clipboardData("event")["getData"]("text/plain")
    let fromThrow = () => throw(Failure("boom"))["m"](Console.log("b"))
Before (diagnostic):
    Warning number 20
    Ex.res:2:46-57
    this argument will not be used by the function.

    Warning number 20
    Ex.res:3:51-66
    this argument will not be used by the function.
After (diagnostic):
    Warning number 20
    Ex.res:3:51-66
    this argument will not be used by the function.

Review: Why does the read record the field type instead of the typed tree
    marking the callee? The Pexp_apply case clears the record, types the
    callee and reads the record right away, comparing it with the callee's
    type by physical equality, so only the callee's own read can match. It
    passes the result to type_application as ~open_row_method. A typed-tree
    flag would change Texp_object_get and the .cmt format for a warning.
Review: Can a read inside an argument replace the callee's record? No:
    the check runs before any argument is typed. The fixture covers
    arguments that read closed and open object fields, first or last, and
    nested method calls.
Review: Why a Request_local key rather than a plain ref? Requests
    type-checked concurrently on separate domains would share a ref, and
    one could overwrite another's record between typing a callee and
    checking it. An ounit test compiles open-object method calls in two
    concurrent requests with warning 20 on and expects none; it failed on
    every run with a shared ref.
Review: Does a method read before the call, `let o = f("e")` then
    `o["m"]` and `o["m"]("used")`, need a record of every field? No: the
    binding keeps the object type at the binding's level, below the level
    of the later call, so the fresh-variable check does not apply.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gJavp7rWUAfzV9rjFj
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt force-pushed the js-object-method-unused-arg-warning branch from ffd35ca to 86453bb Compare November 1, 2026 17:03

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