Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007482OCamltypingpublic2017-02-13 18:452017-02-20 10:38
Reportermlasson 
Assigned Tofrisch 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionduplicate 
PlatformOSOS Version
Product Version 
Target Version4.06.0 +dev/beta1/beta2/rc1Fixed in Version 
Summary0007482: The "unused" checks are confused with "unlocated" code
DescriptionWhen 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 https://github.com/LexiFi/landmarks/issues/9 [^] )
Steps To ReproduceYou 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.
TagsNo tags attached.
Attached Files

- Relationships
duplicate of 0006013confirmed duplicate locations cause 'unused warnings' to be lost 

-  Notes
(0017345)
xleroy (administrator)
2017-02-19 16:57

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?
(0017359)
frisch (developer)
2017-02-20 10:38

Duplicate of 0006013.

- Issue History
Date Modified Username Field Change
2017-02-13 18:45 mlasson New Issue
2017-02-19 16:57 xleroy Note Added: 0017345
2017-02-19 16:57 xleroy Assigned To => frisch
2017-02-19 16:57 xleroy Status new => assigned
2017-02-19 16:57 xleroy Target Version => 4.06.0 +dev/beta1/beta2/rc1
2017-02-20 10:37 frisch Relationship added child of 0006013
2017-02-20 10:38 frisch Relationship replaced duplicate of 0006013
2017-02-20 10:38 frisch Note Added: 0017359
2017-02-20 10:38 frisch Status assigned => resolved
2017-02-20 10:38 frisch Resolution open => duplicate
2017-02-23 16:45 doligez Category OCaml typing => typing


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker