Skip to content

Reanalyze: skip Division_by_zero for non-zero literal divisors - #8917

Merged
cknitt merged 1 commit into
masterfrom
reanalyze-div-const-divisor
Oct 20, 2026
Merged

cknitt merged 1 commit into
masterfrom
reanalyze-div-const-divisor

Conversation

@cknitt

@cknitt cknitt commented Oct 19, 2026

Copy link
Copy Markdown
Member

The reanalyze exception analysis treated every / and mod as possibly throwing Division_by_zero, so x / 10 asked for a @throws annotation. When the divisor is a non-zero int, float or bigint literal, the call no longer counts as throwing. Division by a variable or by a zero literal is still reported.

Fixes #7679.

New test: tests/analysis_tests/tests-reanalyze/deadcode/src/exception/Division.res covers literal, negative-literal, bigint and float divisors (no warning), and variable or zero divisors (warning).

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo

The exception analysis treats `/` and `mod` as throwing Division_by_zero.
It now skips that when the divisor is a non-zero int, float or bigint
literal, so `x / 10` needs no @throws annotation. Divisions by a variable
or by a zero literal are still reported.

Example (rescript):
    let foo = (x: int) => x / 10

Diagnostic (text):
    Before: foo might throw Division_by_zero ... and is not annotated
    with @throws(Division_by_zero)
    After: no warning

Review: Existing `@throws(Division_by_zero)` or `@doesNotThrow` on such
expressions are now reported as redundant, which is correct.

Review: A negated non-literal divisor such as `x / -y` is still reported;
only literal constants are recognised.

Area: reanalyze tests
Output: unchanged
Tests: +tests/analysis_tests/tests-reanalyze/deadcode/src/exception/Division.res
 ~tests/analysis_tests/tests-reanalyze/deadcode/expected/exception.txt
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

@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.33333% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.03%. Comparing base (58da277) to head (9613978).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
analysis/reanalyze/src/exception.ml 73.33% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8917      +/-   ##
==========================================
- Coverage   81.03%   81.03%   -0.01%     
==========================================
  Files         455      455              
  Lines       63640    63654      +14     
==========================================
+ Hits        51573    51583      +10     
- Misses      12067    12071       +4     
Files with missing lines Coverage Δ
analysis/reanalyze/src/exception.ml 80.06% <73.33%> (-0.43%) ⬇️
🚀 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@8917

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 9613978

@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-20T06:09:14.715303Z 9613978 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. Swish!

Reviewed commit: 9613978f37

ℹ️ 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 08:28
@cknitt
cknitt requested a review from cristianoc October 20, 2026 08:28

@cristianoc cristianoc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this based on latest master?
Semantic diff is good but not great.
I think we don't have a reanalyze support at all.
Would you like to add it or I can just try.
I do t think it requires more than ask: add reanalyze support.

@cknitt

cknitt commented Oct 20, 2026

Copy link
Copy Markdown
Member Author

Is this based on latest master?

@cristianoc No, this is from before #8908 was merged.

Would you like to add it or I can just try.

Would be great if you could add the reanalyze support in the semantic diff, I am busy with all those cleanups and fixes anyway. 🙂

@cknitt
cknitt enabled auto-merge (squash) October 20, 2026 11:37

@cristianoc cristianoc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. Please hold the merge for a bit: once semantic diff can draw reanalyze reports (PR coming), I'll rebase this onto master and rewrite its commit message as a record showing the exception analysis Before and After, so it lands with its semantic diff.

@cknitt
cknitt merged commit 87c4b1b into master Oct 20, 2026
28 checks passed
@cknitt
cknitt deleted the reanalyze-div-const-divisor branch October 20, 2026 13:01
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.

[reanalyze] [bug] division_by_zero exception analysis should check constant denominators

2 participants