Skip to content

Commit 37ddbd9

Browse files
committed
Exception analysis: report on toplevel bindings of the form let () = ... and let _ = ....
1 parent 057e2ac commit 37ddbd9

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed

Changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# master
22
- Exception analysis: add support for inner modules.
33
- Exception analysis: correctly hide location of caught exceptions when other instances of the same exception are reported.
4+
- Exception analysis: report on toplevel bindings of the form `let () = ...` and `let _ = ...`.
45

56
# 2.9.0
67
- Model `exit(...)` as raising a fictional exception called `exit`.

examples/deadcode/src/exception.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,20 @@
9191
File "./Exn.res", line 179, characters 4-23
9292
redundantAnnotation raises nothing and is annotated with redundant @raises Invalid_argument
9393

94+
Exception Analysis
95+
File "./Exn.res", line 181, characters 4-6
96+
_x might raise A (Exn.res:181:9) and is not annotated with @raises A
97+
98+
Exception Analysis
99+
File "./Exn.res", line 183, characters 4-5
100+
_ might raise A (Exn.res:183:8) and is not annotated with @raises A
101+
102+
Exception Analysis
103+
File "./Exn.res", line 185, characters 4-6
104+
() might raise A (Exn.res:185:9) and is not annotated with @raises A
105+
94106
Exception Analysis
95107
File "./ExnA.res", line 1, characters 4-7
96108
bar might raise Not_found (ExnA.res:1:16) and is not annotated with @raises Not_found
97109

98-
Analysis reported 24 issues (Exception Analysis:24)
110+
Analysis reported 27 issues (Exception Analysis:27)

examples/deadcode/src/exception/Exn.bs.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/deadcode/src/exception/Exn.res

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,13 @@ let redundant4 = () => {
173173
}
174174

175175
@raises(exit)
176-
let exits = () => exit(1);
176+
let exits = () => exit(1)
177177

178178
@raises(Invalid_argument)
179-
let redundantAnnotation = () => ()
179+
let redundantAnnotation = () => ()
180+
181+
let _x = raise(A)
182+
183+
let _ = raise(A)
184+
185+
let () = raise(A)

src/Exception.re

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,10 @@ let traverseAst = {
586586
res;
587587
};
588588
switch (vb.vb_pat.pat_desc) {
589+
| Tpat_any when isToplevel && !vb.vb_loc.loc_ghost => processBinding("_")
590+
| Tpat_construct({txt: Longident.Lident("()")}, _, _)
591+
when isToplevel && !vb.vb_loc.loc_ghost =>
592+
processBinding("()")
589593
| Tpat_var(id, {loc: {loc_ghost}})
590594
when (isFunction || isToplevel) && !loc_ghost && !vb.vb_loc.loc_ghost =>
591595
processBinding(id |> Ident.name)

0 commit comments

Comments
 (0)