<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Asciidoctor 2.0.26">
<title>WarnUnusedAnomalies</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700">
<link rel="stylesheet" href="./asciidoctor.css">
<link rel="stylesheet" href="./mlton.css">

</head>
<body class="article">
<div id="mlton-header">
<div id="mlton-header-text">
<h2>
<a href="./Home">
MLton
20241230+git20251029+dfsg-5
</a>
</h2>
</div>
</div>
<div id="header">
<h1>WarnUnusedAnomalies</h1>
</div>
<div id="content">
<div class="paragraph">
<p>The <code>warnUnused</code> <a href="MLBasisAnnotations">MLBasis annotation</a> can be used
to report unused identifiers.  This can be useful for catching bugs
and for code maintenance (e.g., eliminating dead code).  However, the
<code>warnUnused</code> annotation can sometimes behave in counter-intuitive
ways.  This page gives some of the anomalies that have been reported.</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Functions whose only uses are recursive uses within their bodies are
not warned as unused:</p>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="sml">local
fun foo () = foo () : unit
val bar = let fun baz () = baz () : unit in baz end
in
end</code></pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre>Warning: z.sml 3.5.
  Unused variable: bar.</pre>
</div>
</div>
</li>
<li>
<p>Components of actual functor argument that are necessary to match
the functor argument signature but are unused in the body of the
functor are warned as unused:</p>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="sml">functor Warning (type t val x : t) = struct
   val y = x
end
structure X = Warning (type t = int val x = 1)</code></pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre>Warning: z.sml 4.29.
  Unused type: t.</pre>
</div>
</div>
</li>
<li>
<p>No component of a functor result is warned as unused.  In the
following, the only uses of <code>f2</code> are to match the functor argument
signatures of <code>functor G</code> and <code>functor H</code> and there are no uses of
<code>z</code>:</p>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="sml">functor F(structure X : sig type t end) = struct
   type t = X.t
   fun f1 (_ : X.t) = ()
   fun f2 (_ : X.t) = ()
   val z = ()
end
functor G(structure Y : sig
                           type t
                           val f1 : t -&gt; unit
                           val f2 : t -&gt; unit
                           val z : unit
                        end) = struct
   fun g (x : Y.t) = Y.f1 x
end
functor H(structure Y : sig
                           type t
                           val f1 : t -&gt; unit
                           val f2 : t -&gt; unit
                           val z : unit
                        end) = struct
   fun h (x : Y.t) = Y.f1 x
end
functor Z() = struct
   structure S = F(structure X = struct type t = unit end)
   structure SG = G(structure Y = S)
   structure SH = H(structure Y = S)
end
structure U = Z()
val _ = U.SG.g ()
val _ = U.SH.h ()</code></pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre></pre>
</div>
</div>
</li>
</ul>
</div>
</div>
</body>
</html>