Skip to content

Commit 362efe1

Browse files
committed
Don't report on module bindings coming from the type of first-class modules.
Fixes #107
1 parent 84888be commit 362efe1

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

Changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# master
2+
- Don't report on module bindings coming from the type of first-class modules (see https://github.com/reason-association/reanalyze/issues/107).
23
- Fix issue where `emptyArray` was reported unused for lowercase components without children. (See https://github.com/reason-association/reanalyze/issues/85).
34

45
# 2.12.0

examples/deadcode/src/FC.bs.js

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

examples/deadcode/src/FC.re

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module type ReplacebleComponent = {
2+
[@react.component]
3+
let make: unit => React.element;
4+
};
5+
6+
let foo = (~impl: (module ReplacebleComponent)) => {
7+
let (module X) = impl;
8+
X.make;
9+
};
10+
11+
Js.log(foo);

examples/deadcode/src/deadcode.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,12 @@
425425
addValueDeclaration +x EverythingLiveHere.re:1:4 path:+EverythingLiveHere
426426
addValueDeclaration +y EverythingLiveHere.re:3:4 path:+EverythingLiveHere
427427
addValueDeclaration +z EverythingLiveHere.re:5:4 path:+EverythingLiveHere
428+
Scanning FC.cmt Source:FC.re
429+
addValueDeclaration +foo FC.re:6:4 path:+FC
430+
addValueReference FC.re:7:14 --> FC.re:6:12
431+
addValueReference FC.re:6:4 --> FC.re:2:2
432+
addValueReference FC.re:6:4 --> FC.re:7:6
433+
addValueReference FC.re:11:7 --> FC.re:6:4
428434
Scanning FirstClassModules.cmt Source:FirstClassModules.re
429435
addValueDeclaration +y FirstClassModules.re:17:6 path:+FirstClassModules.M
430436
addValueDeclaration +k FirstClassModules.re:21:8 path:+FirstClassModules.M.InnerModule2
@@ -1889,6 +1895,7 @@ File References
18891895
ErrorHandler.re -->>
18901896
ErrorHandler.rei -->> ErrorHandler.re
18911897
EverythingLiveHere.re -->>
1898+
FC.re -->>
18921899
FirstClassModules.re -->>
18931900
FirstClassModulesInterface.re -->>
18941901
FirstClassModulesInterface.rei -->> FirstClassModulesInterface.re
@@ -2102,6 +2109,7 @@ File References
21022109
Dead Value +EverythingLiveHere.+z: 0 references () [0]
21032110
Dead Value +EverythingLiveHere.+y: 0 references () [0]
21042111
Dead Value +EverythingLiveHere.+x: 0 references () [0]
2112+
Live Value +FC.+foo: 1 references (FC.re:11:7) [0]
21052113
Live Value +FirstClassModules.+someFunctorAsFunction: 0 references () [0]
21062114
Live Value +FirstClassModules.SomeFunctor.+ww: 1 references (FirstClassModules.re:46:20) [0]
21072115
Live Value +FirstClassModules.+testConvert: 0 references () [0]

src/DeadValue.re

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@ let collectValueBinding = (super, self, vb: Typedtree.value_binding) => {
4848
};
4949
let currentModulePath = ModulePath.getCurrent();
5050
let path = currentModulePath.path @ [Common.currentModuleName^];
51-
if (!exists) {
51+
52+
let isFirstClassModule =
53+
switch (vb.vb_expr.exp_type.desc) {
54+
| Tpackage(_) => true
55+
| _ => false
56+
};
57+
if (!exists && !isFirstClassModule) {
5258
// This is never toplevel currently
5359
let isToplevel = oldLastBinding == Location.none;
5460
let sideEffects = SideEffects.checkExpr(vb.vb_expr);

0 commit comments

Comments
 (0)