Skip to content

Keep @deprecated on let bindings in inferred signatures - #8924

Merged
cknitt merged 2 commits into
masterfrom
deprecated-let-implementation
Oct 20, 2026
Merged

cknitt merged 2 commits into
masterfrom
deprecated-let-implementation

Conversation

@cknitt

@cknitt cknitt commented Oct 19, 2026

Copy link
Copy Markdown
Member

A module without an interface file gets its signature from the implementation, and let-bound values went into it without their attributes. So a @deprecated let never warned in other modules, while @deprecated externals, types and modules did. Each let-bound value's signature item now keeps the binding's @deprecated attributes, and only those. Uses inside the defining structure still do not warn.

Fixes #5335.

New test: tests/build_tests/super_errors_multi/fixtures/Cross_deprecated_res_items uses a deprecated let, external, module and type from another module and expects exactly one warning for each.

Not in this PR: a deprecated item used as an operand of + or another unified operator warns twice, because translate_unified_ops types that operand twice.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo

@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.12%. Comparing base (b7c67d2) to head (97377cf).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #8924   +/-   ##
=======================================
  Coverage   81.11%   81.12%           
=======================================
  Files         455      455           
  Lines       63672    63682   +10     
=======================================
+ Hits        51650    51660   +10     
  Misses      12022    12022           
Files with missing lines Coverage Δ
compiler/ml/builtin_attributes.ml 81.44% <100.00%> (+0.19%) ⬆️
compiler/ml/typemod.ml 73.87% <100.00%> (+0.29%) ⬆️
🚀 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.

A module without an interface file gets its signature from its
implementation. Values bound by `let` entered that signature without
their attributes, so `@deprecated` on a `let` had no effect on other
modules, while `@deprecated` externals, types and modules warned. The
signature item of each let-bound value now carries the binding's
`@deprecated` attributes. Uses inside the defining structure still do
not warn; uses from other modules, and from outside a submodule, do.

Example (rescript):
    // Legacy.res
    @deprecated("Use newF instead")
    let oldF = x => x + 1

    // User.res
    let a = Legacy.oldF(1)

Diagnostic (text):
    Warning number 3
    User.res:1:9-19
    deprecated: Legacy.oldF
    Use newF instead

Review: Only the `deprecated` attributes are copied, so docstrings and
 other binding attributes stay out of the `.cmi` and gentype, analysis and
 reanalyze see the same value descriptions as before.
Review: An implementation with `@deprecated let x` checked against an
 interface whose `let x` lacks it now gets warning 3 ("deprecated: x"),
 as `@deprecated` externals, types and modules already do.
Review: The issue's duplicate warnings come from `translate_unified_ops`
 typing an operand of `+` and the other unified operators twice; any
 warning inside that operand repeats. This change leaves that alone.

Area: typechecker tests
Output: unchanged
Formatting: unchanged
Formats: none
PPX: unchanged
Editor: unchanged in the analysis fixtures; values the analysis reads
 from a module type (`Sig_value`, e.g. through `include`) can now show
 as deprecated
Tests: +tests/build_tests/super_errors_multi/fixtures/Cross_deprecated_res_items
 +tests/build_tests/super_errors_multi/expected/Cross_deprecated_res_items.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 force-pushed the deprecated-let-implementation branch from b9e404c to b92b5e3 Compare October 20, 2026 08:22
With deprecated `let` bindings now reaching other modules, the existing
`@deprecated` on `Pervasives.failwith` and `Pervasives.invalid_arg` warns
at every use. The message now names the replacements. The rewatch test
repository throws `Failure` directly, so the suite's build output stays free
of the warning.

Diagnostic (text):
    Warning number 3
    deprecated: Pervasives.failwith
    Use a custom exception or `JsError.throwWithMessage` instead.

Review: The message has no `migrate` template, because both replacements
 throw a different exception than `Failure` / `Invalid_argument`.
Review: tests/tests, belt_tests and the reanalyze tests still call
 `failwith` and `invalid_arg`; their configurations disable warning 3, so
 they stay unchanged.

Area: runtime tests
Output: changed rewatch/testrepo FileToTest_test.mjs, which throws `Failure`
 inline instead of calling `Pervasives.failwith`
Tests: ~rewatch/testrepo/packages/with-dev-deps/test/FileToTest_test.res
 ~rewatch/testrepo/packages/with-dev-deps/test/FileToTest_test.mjs
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

@pkg-pr-new

pkg-pr-new Bot commented Oct 20, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 97377cf

@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-20T09:43:14.446943Z 97377cf 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

Copy link
Copy Markdown

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

Reviewed commit: 97377cf015

ℹ️ 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 marked this pull request as ready for review October 20, 2026 11:33
@cknitt
cknitt requested a review from cristianoc October 20, 2026 11:33
@cknitt
cknitt merged commit 9f3f1d7 into master Oct 20, 2026
28 checks passed
@cknitt
cknitt deleted the deprecated-let-implementation branch October 20, 2026 12:32
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.

@deprecated decorator does only fully work in interfaces

2 participants