Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005979OCamltypingpublic2013-04-09 20:332017-03-01 17:05
Assigned To 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0005979: New warning for never used optional argument
DescriptionThe 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 Reproduceocamlopt -version

ocamlopt -w +a -c
do not produce any warning.
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

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
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
frisch (developer)
2013-04-10 13:24

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.

- Issue History
Date Modified Username Field Change
2013-04-09 20:33 mbarbin New Issue
2013-04-10 13:24 frisch Note Added: 0009060
2013-06-19 15:22 doligez Status new => acknowledged
2017-02-23 16:36 doligez Category OCaml general => -OCaml general
2017-03-01 17:05 doligez Category -OCaml general => typing

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker