Debian Codegraph @

doc/guide/src/WarnUnusedAnomalies.adoc

raw
1 = WarnUnusedAnomalies
2
3 The `warnUnused` <<MLBasisAnnotations#,MLBasis annotation>> can be used
4 to report unused identifiers. This can be useful for catching bugs
5 and for code maintenance (e.g., eliminating dead code). However, the
6 `warnUnused` annotation can sometimes behave in counter-intuitive
7 ways. This page gives some of the anomalies that have been reported.
8
9 * Functions whose only uses are recursive uses within their bodies are
10 not warned as unused:
11 +
12 [source,sml]
13 ----
14 local
15 fun foo () = foo () : unit
16 val bar = let fun baz () = baz () : unit in baz end
17 in
18 end
19 ----
20 +
21 ----
22 Warning: z.sml 3.5.
23 Unused variable: bar.
24 ----
25
26 * Components of actual functor argument that are necessary to match
27 the functor argument signature but are unused in the body of the
28 functor are warned as unused:
29 +
30 [source,sml]
31 ----
32 functor Warning (type t val x : t) = struct
33 val y = x
34 end
35 structure X = Warning (type t = int val x = 1)
36 ----
37 +
38 ----
39 Warning: z.sml 4.29.
40 Unused type: t.
41 ----
42
43
44 * No component of a functor result is warned as unused. In the
45 following, the only uses of `f2` are to match the functor argument
46 signatures of `functor G` and `functor H` and there are no uses of
47 `z`:
48 +
49 [source,sml]
50 ----
51 functor F(structure X : sig type t end) = struct
52 type t = X.t
53 fun f1 (_ : X.t) = ()
54 fun f2 (_ : X.t) = ()
55 val z = ()
56 end
57 functor G(structure Y : sig
58 type t
59 val f1 : t -> unit
60 val f2 : t -> unit
61 val z : unit
62 end) = struct
63 fun g (x : Y.t) = Y.f1 x
64 end
65 functor H(structure Y : sig
66 type t
67 val f1 : t -> unit
68 val f2 : t -> unit
69 val z : unit
70 end) = struct
71 fun h (x : Y.t) = Y.f1 x
72 end
73 functor Z() = struct
74 structure S = F(structure X = struct type t = unit end)
75 structure SG = G(structure Y = S)
76 structure SH = H(structure Y = S)
77 end
78 structure U = Z()
79 val _ = U.SG.g ()
80 val _ = U.SH.h ()
81 ----
82 +
83 ----
84 ----