You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 86453bb
Browse filesBrowse the repository at this point in the historyBrowse files
Stop warning 20 on calls of open JS object methods
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>
- 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")`.
0 commit comments