You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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.
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.
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
The text was updated successfully, but these errors were encountered: