@@ -13,6 +13,7 @@ module Config = struct
13
13
let analyzeTypes = ref true
14
14
let analyzeExternals = ref false
15
15
let reportUnderscore = false
16
+ let reportTransitive = true
16
17
let reportTypesDeadOnlyInInterface = false
17
18
let recursiveDebug = false
18
19
let warnOnCircularDependencies = false
@@ -375,7 +376,7 @@ let addDeclaration_ ?posEnd ?posStart ~declKind ~path ~(loc : Location.t)
375
376
pos;
376
377
posEnd;
377
378
posStart;
378
- resolved = false ;
379
+ resolvedDead = None ;
379
380
report = true ;
380
381
}
381
382
in
@@ -536,12 +537,21 @@ module Decl = struct
536
537
| VariantCase ->
537
538
(WarningDeadType , " is a variant case which is never constructed" )
538
539
in
540
+ let hasRefBelow () =
541
+ let refs = ValueReferences. find decl.pos in
542
+ let refIsBelow (pos : Lexing.position ) =
543
+ decl.pos.pos_fname <> pos.pos_fname
544
+ || decl.pos.pos_cnum < pos.pos_cnum
545
+ && decl.posEnd.pos_cnum < pos.pos_cnum
546
+ in
547
+ refs |> PosSet. exists refIsBelow
548
+ in
539
549
let shouldEmitWarning =
540
550
(not insideReportedValue)
541
- &&
542
- match decl.path with
543
- | name :: _ when name |> Name. isUnderscore -> Config. reportUnderscore
544
- | _ -> true
551
+ && ( match decl.path with
552
+ | name :: _ when name |> Name. isUnderscore -> Config. reportUnderscore
553
+ | _ -> true )
554
+ && ( Config. reportTransitive || not (hasRefBelow () ))
545
555
in
546
556
if shouldEmitWarning then (
547
557
decl.path
@@ -563,7 +573,7 @@ let doReportDead pos = not (ProcessDeadAnnotations.isAnnotatedGenTypeOrDead pos)
563
573
let rec resolveRecursiveRefs ~checkOptionalArg ~deadDeclarations ~level
564
574
~orderedFiles ~refs ~refsBeingResolved decl : bool =
565
575
match decl.pos with
566
- | _ when decl.resolved ->
576
+ | _ when decl.resolvedDead <> None ->
567
577
if Config. recursiveDebug then
568
578
Log_. item " recursiveDebug %s [%d] already resolved@."
569
579
(decl.path |> Path. toString)
@@ -609,13 +619,13 @@ let rec resolveRecursiveRefs ~checkOptionalArg ~deadDeclarations ~level
609
619
~level: (level + 1 ) ~ordered Files ~refs: xRefs
610
620
~refs BeingResolved
611
621
in
612
- if not xDecl.resolved then allDepsResolved := false ;
622
+ if xDecl.resolvedDead = None then allDepsResolved := false ;
613
623
not xDeclIsDead)
614
624
in
615
625
let isDead = decl |> declIsDead ~refs: newRefs in
616
626
let isResolved = (not isDead) || ! allDepsResolved || level = 0 in
617
627
if isResolved then (
618
- decl.resolved < - true ;
628
+ decl.resolvedDead < - Some isDead ;
619
629
if isDead then (
620
630
decl.path
621
631
|> DeadModules. markDead
@@ -691,4 +701,5 @@ let reportDead ~checkOptionalArg =
691
701
let sortedDeadDeclarations =
692
702
! deadDeclarations |> List. fast_sort Decl. compareForReporting
693
703
in
704
+ (* XXX *)
694
705
sortedDeadDeclarations |> List. iter Decl. report
0 commit comments