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

New warning for never used optional argument #5979

Closed
vicuna opened this issue Apr 9, 2013 · 3 comments
Closed

New warning for never used optional argument #5979

vicuna opened this issue Apr 9, 2013 · 3 comments

Comments

@vicuna
Copy link

vicuna commented Apr 9, 2013

Original bug ID: 5979
Reporter: mbarbin
Status: acknowledged (set by @damiendoligez on 2013-06-19T13:22:07Z)
Resolution: open
Priority: normal
Severity: feature
Category: typing
Monitored by: @alainfrisch

Bug description

The idea behind it is that it helps detecting dead code, and/or makes sure the author is aware of this.

Condition: if a non-exported function within a module, or a local function, has an optional argument and this optional argument is never used by any of the call sites, a warning would be displayed to notify pointing to the optional argument and saying that it is never used.

I honestly haven't given it a fair amount of thoughts, and I believe that it does not play too well if the function are passed dynamically as arguments, etc. However, it seems plausible that even if this warning were be triggered by top-level function that are never passed, it would already be very useful.

This might be a duplicated mantis item too, although I couldn't find an exact similar one.

Steps to reproduce

ocamlopt -version
4.00.1

ocamlopt -w +a -c a.ml
do not produce any warning.

a.ml:

module A : sig
type t
val add : t -> t -> int
end = struct
type t = int
let add a b =
let aux ?(a=0) b c = a + b + c in
aux a b
end

module B : sig
type t
val add : t -> t -> int
end = struct
type t = int
let aux ?(a=0) b c = a + b + c
let add a b =
aux a b
end

@vicuna
Copy link
Author

vicuna commented Apr 10, 2013

Comment author: @alainfrisch

Agreed, detecting such unused optional argument is very useful! It's also useful to detect optional argument which are always passed (i.e. could be turned to non-optional ones), and one could go even further and detect arguments (labeled/optional/regular) which are always passed a "similar" value (e.g. same toplevel constructor for a sum type). We have a tool at LexiFi based on reading .cmt files which implements such detection for an entire code base, but I agree that the simple case of detecting unused optional arguments within a single compilation unit would already be useful in the compiler itself.

@github-actions
Copy link

This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc.

@Alizter
Copy link
Contributor

Alizter commented May 25, 2022

Is this simple to implement? I think it would be a useful feature.

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