Skip to content

Commit 14e8772

Browse files
committed
Fix issue where code analysis would not track types in inner modules across implementations and interfaces
Fixes rescript-lang/reanalyze#186
1 parent a61cc75 commit 14e8772

File tree

8 files changed

+47
-2
lines changed

8 files changed

+47
-2
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737

3838
- Fix issue with completing `foo. x` where `x` should not be part of the completion https://github.com/rescript-lang/rescript-vscode/pull/644
3939

40+
- Fix issue where code analysis would not track types in inner modules across implementations and interfaces https://github.com/rescript-association/reanalyze/issues/186
41+
4042
## v1.8.2
4143

4244
#### :rocket: New Feature

Diff for: analysis/reanalyze/examples/deadcode/expected/deadcode.txt

+17
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,14 @@
11001100
addValueDeclaration +make ImportMyBanner.res:12:4 path:+ImportMyBanner
11011101
addRecordLabelDeclaration text ImportMyBanner.res:5:16 path:+ImportMyBanner.message
11021102
addValueReference ImportMyBanner.res:12:4 --> ImportMyBanner.res:7:0
1103+
Scanning InnerModuleTypes.cmt Source:InnerModuleTypes.res
1104+
addVariantCaseDeclaration Foo InnerModuleTypes.res:2:11 path:+InnerModuleTypes.I.t
1105+
Scanning InnerModuleTypes.cmti Source:InnerModuleTypes.resi
1106+
addVariantCaseDeclaration Foo InnerModuleTypes.resi:2:11 path:InnerModuleTypes.I.t
1107+
extendTypeDependencies InnerModuleTypes.res:2:11 --> InnerModuleTypes.resi:2:11
1108+
extendTypeDependencies InnerModuleTypes.resi:2:11 --> InnerModuleTypes.res:2:11
1109+
addTypeReference InnerModuleTypes.res:2:11 --> InnerModuleTypes.resi:2:11
1110+
addTypeReference InnerModuleTypes.resi:2:11 --> InnerModuleTypes.res:2:11
11031111
Scanning JSResource.cmt Source:JSResource.res
11041112
Scanning JsxV4.cmt Source:JsxV4.res
11051113
addValueDeclaration +make JsxV4.res:4:23 path:+JsxV4.C
@@ -1496,6 +1504,9 @@
14961504
addValueReference TestImport.res:13:4 --> TestImport.res:1:0
14971505
addRecordLabelDeclaration text TestImport.res:22:16 path:+TestImport.message
14981506
addValueReference TestImport.res:27:4 --> TestImport.res:24:0
1507+
Scanning TestInnedModuleTypes.cmt Source:TestInnedModuleTypes.res
1508+
addValueDeclaration +_ TestInnedModuleTypes.res:1:0 path:+TestInnedModuleTypes
1509+
addTypeReference TestInnedModuleTypes.res:1:8 --> InnerModuleTypes.resi:2:11
14991510
Scanning TestModuleAliases.cmt Source:TestModuleAliases.res
15001511
addValueDeclaration +testInner1 TestModuleAliases.res:32:4 path:+TestModuleAliases
15011512
addValueDeclaration +testInner1Expanded TestModuleAliases.res:35:4 path:+TestModuleAliases
@@ -1890,6 +1901,8 @@ File References
18901901
ImportIndex.res -->>
18911902
ImportJsValue.res -->>
18921903
ImportMyBanner.res -->>
1904+
InnerModuleTypes.res -->>
1905+
InnerModuleTypes.resi -->>
18931906
JSResource.res -->>
18941907
JsxV4.res -->> React.res
18951908
LetPrivate.res -->>
@@ -1914,6 +1927,7 @@ File References
19141927
TestFirstClassModules.res -->>
19151928
TestImmutableArray.res -->> ImmutableArray.resi
19161929
TestImport.res -->>
1930+
TestInnedModuleTypes.res -->>
19171931
TestModuleAliases.res -->>
19181932
TestOptArg.res -->> OptArg.resi
19191933
TestPromise.res -->>
@@ -2126,6 +2140,8 @@ File References
21262140
Dead Value +ImportMyBanner.+make: 0 references () [0]
21272141
Live Value +ImportMyBanner.+make: 0 references () [0]
21282142
Dead RecordLabel +ImportMyBanner.message.text: 0 references () [0]
2143+
Live VariantCase InnerModuleTypes.I.t.Foo: 1 references (TestInnedModuleTypes.res:1:8) [1]
2144+
Live VariantCase +InnerModuleTypes.I.t.Foo: 1 references (InnerModuleTypes.resi:2:11) [0]
21292145
Live Value +JsxV4.C.+make: 1 references (JsxV4.res:7:9) [0]
21302146
Live Value +LetPrivate.+y: 0 references () [0]
21312147
Live Value +LetPrivate.local_1.+x: 1 references (LetPrivate.res:7:4) [0]
@@ -2269,6 +2285,7 @@ File References
22692285
Dead Value +TestImport.+innerStuffContents: 0 references () [0]
22702286
Live Value +TestImport.+innerStuffContentsAsEmptyObject: 0 references () [0]
22712287
Live Value +TestImport.+innerStuffContents: 0 references () [0]
2288+
Dead Value +TestInnedModuleTypes.+_: 0 references () [0]
22722289
Live Value +TestModuleAliases.+testInner2Expanded: 0 references () [0]
22732290
Live Value +TestModuleAliases.+testInner2: 0 references () [0]
22742291
Live Value +TestModuleAliases.+testInner1Expanded: 0 references () [0]

Diff for: analysis/reanalyze/examples/deadcode/src/InnerModuleTypes.bs.js

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module I = {
2+
type t = Foo
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module I: {
2+
type t = Foo
3+
}

Diff for: analysis/reanalyze/examples/deadcode/src/TestInnedModuleTypes.bs.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let _ = InnerModuleTypes.I.Foo

Diff for: analysis/reanalyze/src/DeadValue.ml

+10-2
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ let rec getSignature (moduleType : Types.module_type) =
234234

235235
let rec processSignatureItem ~doTypes ~doValues ~moduleLoc ~path
236236
(si : Types.signature_item) =
237-
match si with
237+
let oldModulePath = ModulePath.getCurrent () in
238+
(match si with
238239
| Sig_type (id, t, _) when doTypes ->
239240
if !Config.analyzeTypes then
240241
DeadType.addDeclaration ~typeId:id ~typeKind:t.type_kind
@@ -260,6 +261,12 @@ let rec processSignatureItem ~doTypes ~doValues ~moduleLoc ~path
260261
~sideEffects:false
261262
| Sig_module (id, {Types.md_type = moduleType; md_loc = moduleLoc}, _)
262263
| Sig_modtype (id, {Types.mtd_type = Some moduleType; mtd_loc = moduleLoc}) ->
264+
ModulePath.setCurrent
265+
{
266+
oldModulePath with
267+
loc = moduleLoc;
268+
path = (id |> Ident.name |> Name.create) :: oldModulePath.path;
269+
};
263270
let collect =
264271
match si with
265272
| Sig_modtype _ -> false
@@ -270,7 +277,8 @@ let rec processSignatureItem ~doTypes ~doValues ~moduleLoc ~path
270277
|> List.iter
271278
(processSignatureItem ~doTypes ~doValues ~moduleLoc
272279
~path:((id |> Ident.name |> Name.create) :: path))
273-
| _ -> ()
280+
| _ -> ());
281+
ModulePath.setCurrent oldModulePath
274282

275283
(* Traverse the AST *)
276284
let traverseStructure ~doTypes ~doExternals =

0 commit comments

Comments
 (0)