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

Warning for unused variables fails with recursive functions #4960

Closed
vicuna opened this issue Jan 14, 2010 · 1 comment
Closed

Warning for unused variables fails with recursive functions #4960

vicuna opened this issue Jan 14, 2010 · 1 comment
Assignees

Comments

@vicuna
Copy link

vicuna commented Jan 14, 2010

Original bug ID: 4960
Reporter: @mmottl
Assigned to: @alainfrisch
Status: closed (set by @alainfrisch on 2011-12-22T11:49:37Z)
Resolution: duplicate
Priority: normal
Severity: minor
Version: 3.11.1
Category: ~DO NOT USE (was: OCaml general)
Child of: #5438
Monitored by: mehdi @ygrek "Julien Signoles" @hcarty yminsky @alainfrisch @mmottl

Bug description

The following function clearly does not make use of the recursive function "loop" in its body, i.e. this loop is dead code. Nevertheless the compiler does not warn about this, probably because the recursive call to "loop" is considered sufficient.

let f () =
let rec loop () =
print_endline "foo";
loop ()
in
42

@vicuna
Copy link
Author

vicuna commented Jan 14, 2010

Comment author: @alainfrisch

Another case of incompleteness of the warning is related to local open (even without the new explicit local open construction):

module A = struct let x = 1 end
let f () = let x = 2 in let module M = struct open A let a = x + 1 end in ()

Here the local "let x = ..." is not used. To see this, the check should be implemented in the type-checker, not as a purely syntactic pass. Doing the detection in the type-checker opens the door to more powerful detection of useless declaration (e.g. module components [types, values] which are not used internally and are hidden by the signature). We use such a patch at LexiFi, and it helped us find a lot of dead code and a few bugs.

Another example with classes:

class c = object val x = 1 end
let f () = let x = 2 in object inherit o method y = x end

or even, simply:

let f () = let x = 2 in object val x = 1 method y = x end

(this last example could probably be fixed even with the current syntactic approach).

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