Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The "unused" checks are confused with "unlocated" code #7482

Closed
vicuna opened this issue Feb 13, 2017 · 2 comments
Closed

The "unused" checks are confused with "unlocated" code #7482

vicuna opened this issue Feb 13, 2017 · 2 comments
Assignees
Milestone

Comments

@vicuna
Copy link

vicuna commented Feb 13, 2017

Original bug ID: 7482
Reporter: @mlasson
Assigned to: @alainfrisch
Status: resolved (set by @alainfrisch on 2017-02-20T09:38:42Z)
Resolution: duplicate
Priority: normal
Severity: minor
Target version: 4.06.0 +dev/beta1/beta2/rc1
Category: typing
Duplicate of: #6013
Monitored by: @diml

Bug description

When compiling

  let f = ()
    let () =
      let f = () in (* unused *)
      ()

one gets a "Warning: unused variable f", which is fine.

But if you craft this piece of code in a ppx extension that does
not locate its identifiers (or that locate them at the same place),
the warning will not be triggered.

This is because these checks are implemented using hash tables with
the "located name" used as a key, so the two occurrences of "f" are
seen as used (because the first one is).

( Note that this was "discovered" while investigating this issue LexiFi/landmarks#9 )

Steps to reproduce

You can try by compiling :

let str = [%str
    let f = ()
    let () =
      let f = () in
      ()
   ]

let () =
  let open Ast_mapper in
  register "landmarks"
    (fun _ ->
      { default_mapper with
        structure = (fun _ _ -> str)})

with ocamlfind ocamlopt -package ppx_tools.metaquot -package compiler-libs.common -linkpkg -o ppx_bug ppx_bug.ml (it requires ocamlfind and ppx_tools).

And then use the ppx to compile any file (eg. "test.ml"):
ocamlc -ppx ./ppx_bug -dsource test.ml.
It will output:
let f = ()
let () = let f = () in ()
And not trigger any warning.

@vicuna
Copy link
Author

vicuna commented Feb 19, 2017

Comment author: @xavierleroy

I have a feeling that we'll have to live with this issue. @Frisch: as the original author of this unused variable analysis, would you please handle this PR?

@vicuna
Copy link
Author

vicuna commented Feb 20, 2017

Comment author: @alainfrisch

Duplicate of #6013.

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

No branches or pull requests

2 participants