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