Skip to content

Methods are not analyzed if a factory function's object is bound before returning #67

@fantazio

Description

@fantazio

Context

If a factory function binds its result (with or without manipulating the binding) before returning it, then its methods are not tracked.

Example and reproduction

(* /tmp/bind_before_return/bind_before_return.ml *)
let factory () =
  let res =
    object
      method used = ()
      method unused = ()
    end
  in
  res

let () = (factory ())#used
$ ocamlopt -bin-annot bind_before_return.ml
$ dead_code_analyzer --nothing -M all bind_before_return.cmi bind_before_return.cmt
Scanning files...
 [DONE]

.> UNUSED METHODS:
=================

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

We can see that there is not unused method reported although factory#unused should be reported. Without the binding to res in factory, the results are:

Scanning files...
 [DONE]

.> UNUSED METHODS:
=================
/tmp/bind_before_return/bind_before_return.ml:2: factory#unused

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions