Repository navigation
Reanalyze: skip Division_by_zero for non-zero literal divisors - #8917
Conversation
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>
Codecov Report❌ Patch coverage is
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
🚀 New features to boost your workflow:
|
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
|
Developer playground preview: https://rescript-lang.github.io/rescript/dev-playground/?version=pr-8917 |
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
cristianoc
left a comment
There was a problem hiding this comment.
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.
@cristianoc No, this is from before #8908 was merged.
Would be great if you could add the reanalyze support in the semantic diff, I am busy with all those cleanups and fixes anyway. 🙂 |
cristianoc
left a comment
There was a problem hiding this comment.
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.
The reanalyze exception analysis treated every
/andmodas possibly throwingDivision_by_zero, sox / 10asked for a@throwsannotation. 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.rescovers 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