|
8 | 8 | + [Warning 32: unused-value-declaration](#warning-32-unused-value-declaration) |
9 | 9 | + [Usage](#usage) |
10 | 10 | + [Examples](#examples) |
| 11 | ++ [Limitations](#limitations) |
11 | 12 |
|
12 | 13 | # Exported Values |
13 | 14 |
|
@@ -212,3 +213,106 @@ Warning 26 [unused-var]: unused variable y. |
212 | 213 | - [Module type](./code_constructs/MODTYP.md) |
213 | 214 | - [Module signature](./code_constructs/MODSIG.md) |
214 | 215 | - [Include](./code_constructs/INCLUDE.md) |
| 216 | + |
| 217 | +# Limitations |
| 218 | + |
| 219 | +## Module type |
| 220 | + |
| 221 | +Related issue : |
| 222 | +[issue #50](https://github.com/LexiFi/dead_code_analyzer/issues/50). |
| 223 | + |
| 224 | +As explained in the [Module type](./code_constructs/MODTYP.md) example, the |
| 225 | +analyzer is currently restrcited to not reporting values declared in module |
| 226 | +types. This means that any unused value defined by a module with a module type |
| 227 | +as signature, even with constraints or substitutions, will not be reported. |
| 228 | + |
| 229 | +A future improvement would be to report unused exported values declared in |
| 230 | +module types by considering all the values defined in modules of such types as |
| 231 | +instances of the values in the module types. |
| 232 | + |
| 233 | +## Include module type with substitution |
| 234 | + |
| 235 | +Related issue : |
| 236 | +[issue #64](https://github.com/LexiFi/dead_code_analyzer/issues/64). |
| 237 | + |
| 238 | +According to the above limitation on values in module types, values included |
| 239 | +from a module type should not be reported. Even more so according to the |
| 240 | +semantics described in the [Include](./code_constructs/INCLUDE.md) example. |
| 241 | +This is the case unless there is a substitution on the module type. |
| 242 | + |
| 243 | +### Example |
| 244 | + |
| 245 | +The reference files for this example are in the |
| 246 | +[sigincl](../../../examples/docs/exported_values/limitations/sigincl) directory. |
| 247 | + |
| 248 | +The reference takes place in `/tmp/docs/exported_values/limitations`, which |
| 249 | +is a copy of the [limitations](../../../examples/docs/exported_values/limitations) |
| 250 | +directory. Reported locations may differ depending on the location of the source |
| 251 | +files. |
| 252 | + |
| 253 | +The compilation command is : |
| 254 | +``` |
| 255 | +make -C sigincl build |
| 256 | +``` |
| 257 | + |
| 258 | +The analysis command is : |
| 259 | +``` |
| 260 | +make -C sigincl analyze |
| 261 | +``` |
| 262 | + |
| 263 | +The compile + analyze command is : |
| 264 | +``` |
| 265 | +make -C sigincl |
| 266 | +``` |
| 267 | + |
| 268 | +Code: |
| 269 | +```OCaml |
| 270 | +(* sigincl_lib.mli *) |
| 271 | +module type T = sig |
| 272 | + type t |
| 273 | + val x : t |
| 274 | +end |
| 275 | +
|
| 276 | +module M : T |
| 277 | +
|
| 278 | +module I : sig |
| 279 | + include T with type t := unit |
| 280 | +end |
| 281 | +``` |
| 282 | +```OCaml |
| 283 | +(* sigincl_lib.ml *) |
| 284 | +module type T = sig |
| 285 | + type t |
| 286 | + val x : t |
| 287 | +end |
| 288 | +
|
| 289 | +module M = struct |
| 290 | + type t = unit |
| 291 | + let x = () |
| 292 | +end |
| 293 | +
|
| 294 | +module I = M |
| 295 | +``` |
| 296 | + |
| 297 | +Compile and analyze: |
| 298 | +``` |
| 299 | +$ make -C sigincl |
| 300 | +make: Entering directory '/tmp/limitations/sigincl' |
| 301 | +ocamlopt -bin-annot sigincl_lib.mli sigincl_lib.ml |
| 302 | +dead_code_analyzer --nothing -E all . |
| 303 | +Scanning files... |
| 304 | + [DONE] |
| 305 | +
|
| 306 | +.> UNUSED EXPORTED VALUES: |
| 307 | +========================= |
| 308 | +/tmp/limitations/sigincl/sigincl_lib.mli:10: I.x |
| 309 | +
|
| 310 | +Nothing else to report in this section |
| 311 | +-------------------------------------------------------------------------------- |
| 312 | +
|
| 313 | +
|
| 314 | +make: Leaving directory '/tmp/limitations/sigincl' |
| 315 | +``` |
| 316 | + |
| 317 | +The analyzer reports `I.x` at the line where `T` is included although it is |
| 318 | +actually declared in `T`. |
0 commit comments