Skip to content

Commit

Permalink
Add warning for unused labels
Browse files Browse the repository at this point in the history
  • Loading branch information
lpw25 committed Feb 19, 2021
1 parent dd7da9a commit 924b0d5
Show file tree
Hide file tree
Showing 10 changed files with 276 additions and 102 deletions.
2 changes: 1 addition & 1 deletion man/ocamlc.m
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ compilation in any way (even if it is fatal). If a warning is enabled,

.IP
The default setting is
.BR \-w\ +a\-4\-6\-7\-9\-27\-29\-30\-32..42\-44\-45\-48\-50\-60\-66\-67\-68 .
.BR \-w\ +a\-4\-6\-7\-9\-27\-29\-30\-32..42\-44\-45\-48\-50\-60\-66..69 .
Note that warnings
.BR 5 \ and \ 10
are not always triggered, depending on the internals of the type checker.
Expand Down
26 changes: 26 additions & 0 deletions testsuite/tests/typing-warnings/unused_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,14 @@ module Unused_record : sig end = struct
let _ = foo
end;;
[%%expect {|
Line 2, characters 13-21:
2 | type t = { a : int; b : int }
^^^^^^^^
Warning 69 [unused-field]: unused record field a.
Line 2, characters 22-29:
2 | type t = { a : int; b : int }
^^^^^^^
Warning 69 [unused-field]: unused record field b.
module Unused_record : sig end
|}]

Expand All @@ -362,6 +370,11 @@ module Unused_field : sig end = struct
let _ = foo
end;;
[%%expect {|
Line 2, characters 13-20:
2 | type t = { a : int }
^^^^^^^
Warning 69 [unused-field]: record field a is never read.
(However, this field is used to build or mutate values.)
module Unused_field : sig end
|}]

Expand All @@ -373,6 +386,11 @@ module Unused_field : sig end = struct
let _ = foo, bar, baz
end;;
[%%expect {|
Line 2, characters 22-30:
2 | type t = { a : int; b : int; c : int }
^^^^^^^^
Warning 69 [unused-field]: record field b is never read.
(However, this field is used to build or mutate values.)
module Unused_field : sig end
|}]

Expand All @@ -383,6 +401,10 @@ module Unused_mutable_field : sig end = struct
let _ = foo, bar
end;;
[%%expect {|
Line 2, characters 22-37:
2 | type t = { a : int; mutable b : int }
^^^^^^^^^^^^^^^
Warning 69 [unused-field]: mutable record field b is never mutated.
module Unused_mutable_field : sig end
|}]

Expand Down Expand Up @@ -414,6 +436,10 @@ end = struct
let _ = foo
end;;
[%%expect {|
Line 4, characters 22-37:
4 | type t = { a : int; mutable b : int }
^^^^^^^^^^^^^^^
Warning 69 [unused-field]: mutable record field b is never mutated.
module Unused_mutable_field_exported_private :
sig type t = private { a : int; mutable b : int; } end
|}]
2 changes: 1 addition & 1 deletion toplevel/native/topeval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ let load_lambda ppf ~module_ident ~required_globals lam size =
else Closure_middle_end.lambda_to_clambda
in
Asmgen.compile_implementation ~toplevel:need_symbol
~backend ~filename ~prefixname:filename
~backend ~prefixname:filename
~middle_end ~ppf_dump:ppf program;
Asmlink.call_linker_shared [filename ^ ext_obj] dll;
Sys.remove (filename ^ ext_obj);
Expand Down

0 comments on commit 924b0d5

Please sign in to comment.