Skip to content

[BUG] object%js with references to self can trigger false unused variable warnings #2125

@johnridesabike

Description

@johnridesabike

Describe the bug

If using references to "self"/"this" with object%js, and any methods do not use that variable, it triggers an unused variable warning. Minimal example:

let () =
  Js_of_ocaml.Js.export_all
    object%js (self)
      method foo = self
      method bar = ()
    end
3 |     object%js (self)
                  ^^^^^^
Error (warning 27 [unused-var-strict]): unused variable self.

Expected behavior
The above example should not trigger the warning.

Looking at the PPX output, it seems that self gets added as an argument to each method function, so the presence of bar is what triggers the warning in this case. Adding more methods triggers the warning more times.

Versions
Version of packages used to reproduce the bug

$ opam list --search js_of_ocaml --installed
# Packages matching: match(*js_of_ocaml*) & installed
# Name               # Installed # Synopsis
brr                  0.0.8       Browser programming toolkit for OCaml
js_of_ocaml          6.2.0       Compiler from OCaml bytecode to JavaScript
js_of_ocaml-compiler 6.2.0       Compiler from OCaml bytecode to JavaScript
js_of_ocaml-ppx      6.2.0       Compiler from OCaml bytecode to JavaScript
js_of_ocaml-toplevel 6.2.0       Compiler from OCaml bytecode to JavaScript
tyxml                4.6.0       A library for building correct HTML and SVG documents

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions