Skip to content

Constructors uses are not tracked through type equations #79

Description

@fantazio

Context

This is a pattern observed in Opam 2.5.1. A variant type is defined in a compilation unit (Either.t), aliased via a type equation in another one (either), and the alias's constructors are used (here and here) but the original constructors are never built.

This leads the analyzer to report the original constructors as unused, although they are via the alias.

If the original type definition and the type equation appear in the same compilation unit (even in different modules), then the analyzer correctly considers the original constructors as used.

Example and reproduction

(* /tmp/type_eq/original.ml *)
type t = UsedByOriginal | UsedByAlias | Unused

let _ = UsedByOriginal
(* /tmp/type_eq/alias.ml *)
type t = Original.t = UsedByOriginal | UsedByAlias | Unused

let _ = UsedByAlias
$ ocamlopt -bin-annot original.ml alias.ml 
$ dead_code_analyzer --nothing -T all .
Scanning files...
 [DONE]

.> UNUSED CONSTRUCTORS/RECORD FIELDS:
====================================
/tmp/type_eq/original.ml:2: t.UsedByAlias
/tmp/type_eq/original.ml:2: t.Unused

Nothing else to report in this section
--------------------------------------------------------------------------------

Among the 3 constructors, t.UsedByOriginal is correctly not reported and t.Unused is correctly reported. However, t.UsedByAlias should not be reported.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions