Skip to content

Commit 7d96fe3

Browse files
authored
Remove dead and unreachable error and warning variants (#8459)
1 parent eb189fd commit 7d96fe3

45 files changed

Lines changed: 407 additions & 438 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
- Cache OPAM env, rewatch build, and instrumented dune state in the coverage workflow. https://github.com/rescript-lang/rescript/pull/8434
5858
- Add a multi-file fixture harness (`super_errors_multi`) for cross-module errors and warnings. https://github.com/rescript-lang/rescript/pull/8433
5959
- Catalog every named compiler error variant in `tests/ERROR_VARIANTS.md` and add fixtures for the remaining reachable ones. https://github.com/rescript-lang/rescript/pull/8446
60+
- Remove dead and unreachable compiler error and warning variants; add fixtures for the ones found to be reachable. https://github.com/rescript-lang/rescript/pull/8459
6061

6162

6263
# 13.0.0-alpha.4

compiler/common/bs_warnings.ml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,3 @@
2424

2525
let warn_literal_overflow loc =
2626
Location.prerr_warning loc Bs_integer_literal_overflow
27-
28-
let error_unescaped_delimiter loc txt =
29-
Location.prerr_warning loc (Bs_uninterpreted_delimiters txt)

compiler/common/bs_warnings.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,3 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

2525
val warn_literal_overflow : Location.t -> unit
26-
27-
val error_unescaped_delimiter : Location.t -> string -> unit

compiler/ext/warnings.ml

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,13 @@ type loc = {
2929
type top_level_unit_help = FunctionCall | Other
3030

3131
type t =
32-
| Comment_start (* 1 *)
33-
| Comment_not_end (* 2 *)
3432
| Deprecated of string * loc * loc * bool (* 3 *)
3533
| Fragile_match of string (* 4 *)
3634
| Partial_application (* 5 *)
37-
| Method_override of string list (* 7 *)
3835
| Partial_match of string (* 8 *)
3936
| Non_closed_record_pattern of string (* 9 *)
40-
| Statement_type (* 10 *)
4137
| Unused_match (* 11 *)
4238
| Unused_pat (* 12 *)
43-
| Instance_variable_override of string list (* 13 *)
44-
| Illegal_backslash (* 14 *)
45-
| Implicit_public_methods of string list (* 15 *)
46-
| Unerasable_optional_argument (* 16 *)
4739
| Unused_argument (* 20 *)
4840
| Nonreturning_statement (* 21 *)
4941
| Preprocessor of string (* 22 *)
@@ -53,7 +45,6 @@ type t =
5345
| Unused_var of string (* 26 *)
5446
| Unused_var_strict of string (* 27 *)
5547
| Wildcard_arg_to_constant_constr (* 28 *)
56-
| Eol_in_string (* 29 *)
5748
| Duplicate_definitions of string * string * string * string (*30 *)
5849
| Unused_value_declaration of string (* 32 *)
5950
| Unused_open of string (* 33 *)
@@ -67,9 +58,7 @@ type t =
6758
| Open_shadow_identifier of string * string (* 44 *)
6859
| Open_shadow_label_constructor of string * string (* 45 *)
6960
| Attribute_payload of string * string (* 47 *)
70-
| Eliminated_optional_arguments of string list (* 48 *)
7161
| No_cmi_file of string * string option (* 49 *)
72-
| Bad_docstring of bool (* 50 *)
7362
| Fragile_literal_pattern (* 52 *)
7463
| Misplaced_attribute of string (* 53 *)
7564
| Duplicated_attribute of string (* 54 *)
@@ -81,10 +70,7 @@ type t =
8170
| Bs_polymorphic_comparison (* 102 *)
8271
| Bs_ffi_warning of string (* 103 *)
8372
| Bs_derive_warning of string (* 104 *)
84-
| Bs_fragile_external of string (* 105 *)
85-
| Bs_unimplemented_primitive of string (* 106 *)
8673
| Bs_integer_literal_overflow (* 107 *)
87-
| Bs_uninterpreted_delimiters of string (* 108 *)
8874
| Bs_toplevel_expression_unit of
8975
(string * top_level_unit_help) option (* 109 *)
9076
| Bs_todo of string option (* 110 *)
@@ -96,21 +82,13 @@ type t =
9682
*)
9783

9884
let number = function
99-
| Comment_start -> 1
100-
| Comment_not_end -> 2
10185
| Deprecated _ -> 3
10286
| Fragile_match _ -> 4
10387
| Partial_application -> 5
104-
| Method_override _ -> 7
10588
| Partial_match _ -> 8
10689
| Non_closed_record_pattern _ -> 9
107-
| Statement_type -> 10
10890
| Unused_match -> 11
10991
| Unused_pat -> 12
110-
| Instance_variable_override _ -> 13
111-
| Illegal_backslash -> 14
112-
| Implicit_public_methods _ -> 15
113-
| Unerasable_optional_argument -> 16
11492
| Unused_argument -> 20
11593
| Nonreturning_statement -> 21
11694
| Preprocessor _ -> 22
@@ -120,7 +98,6 @@ let number = function
12098
| Unused_var _ -> 26
12199
| Unused_var_strict _ -> 27
122100
| Wildcard_arg_to_constant_constr -> 28
123-
| Eol_in_string -> 29
124101
| Duplicate_definitions _ -> 30
125102
| Unused_value_declaration _ -> 32
126103
| Unused_open _ -> 33
@@ -134,9 +111,7 @@ let number = function
134111
| Open_shadow_identifier _ -> 44
135112
| Open_shadow_label_constructor _ -> 45
136113
| Attribute_payload _ -> 47
137-
| Eliminated_optional_arguments _ -> 48
138114
| No_cmi_file _ -> 49
139-
| Bad_docstring _ -> 50
140115
| Fragile_literal_pattern -> 52
141116
| Misplaced_attribute _ -> 53
142117
| Duplicated_attribute _ -> 54
@@ -148,10 +123,7 @@ let number = function
148123
| Bs_polymorphic_comparison -> 102
149124
| Bs_ffi_warning _ -> 103
150125
| Bs_derive_warning _ -> 104
151-
| Bs_fragile_external _ -> 105
152-
| Bs_unimplemented_primitive _ -> 106
153126
| Bs_integer_literal_overflow -> 107
154-
| Bs_uninterpreted_delimiters _ -> 108
155127
| Bs_toplevel_expression_unit _ -> 109
156128
| Bs_todo _ -> 110
157129

@@ -297,8 +269,6 @@ let reset () =
297269
let () = reset ()
298270

299271
let message = function
300-
| Comment_start -> "this is the start of a comment."
301-
| Comment_not_end -> "this is not the end of a comment."
302272
| Deprecated (s, _, _, can_be_automigrated) ->
303273
(* Reduce \r\n to \n:
304274
- Prevents any \r characters being printed on Unix when processing
@@ -321,12 +291,6 @@ let message = function
321291
It will remain exhaustive when constructors are added to type " ^ s ^ "."
322292
| Partial_application ->
323293
"this function application is partial,\nmaybe some arguments are missing."
324-
| Method_override [lab] -> "the method " ^ lab ^ " is overridden."
325-
| Method_override (cname :: slist) ->
326-
String.concat " "
327-
("the following methods are overridden by the class" :: cname :: ":\n "
328-
:: slist)
329-
| Method_override [] -> assert false
330294
| Partial_match "" ->
331295
"You forgot to handle a possible case here, though we don't have more \
332296
information on the value."
@@ -335,42 +299,8 @@ let message = function
335299
| Non_closed_record_pattern s ->
336300
"the following labels are not bound in this record pattern: " ^ s
337301
^ "\nEither bind these labels explicitly or add ', _' to the pattern."
338-
| Statement_type ->
339-
"This expression returns a value, but you're not doing anything with it. \
340-
If this is on purpose, wrap it with `ignore`."
341302
| Unused_match -> "this match case is unused."
342303
| Unused_pat -> "this sub-pattern is unused."
343-
| Instance_variable_override [lab] ->
344-
"the instance variable " ^ lab ^ " is overridden.\n"
345-
^ "The behaviour changed in ocaml 3.10 (previous behaviour was hiding.)"
346-
| Instance_variable_override (cname :: slist) ->
347-
String.concat " "
348-
("the following instance variables are overridden by the class" :: cname
349-
:: ":\n " :: slist)
350-
^ "\nThe behaviour changed in ocaml 3.10 (previous behaviour was hiding.)"
351-
| Instance_variable_override [] -> assert false
352-
| Illegal_backslash -> "illegal backslash escape in string."
353-
| Implicit_public_methods l ->
354-
"the following private methods were made public implicitly:\n "
355-
^ String.concat " " l ^ "."
356-
| Unerasable_optional_argument ->
357-
String.concat ""
358-
[
359-
"This optional parameter in final position will, in practice, not be \
360-
optional.\n";
361-
" Reorder the parameters so that at least one non-optional one is in \
362-
final position or, if all parameters are optional, insert a final \
363-
().\n\n";
364-
" Explanation: If the final parameter is optional, it'd be unclear \
365-
whether a function application that omits it should be considered \
366-
fully applied, or partially applied. Imagine writing `let title = \
367-
display(\"hello!\")`, only to realize `title` isn't your desired \
368-
result, but a curried call that takes a final optional argument, e.g. \
369-
`~showDate`.\n\n";
370-
" Formal rule: an optional argument is considered intentionally \
371-
omitted when the 1st positional (i.e. neither labeled nor optional) \
372-
argument defined after it is passed in.";
373-
]
374304
| Unused_argument -> "this argument will not be used by the function."
375305
| Nonreturning_statement ->
376306
"This statement does not continue execution; following code is unreachable."
@@ -398,8 +328,6 @@ let message = function
398328
v v
399329
| Wildcard_arg_to_constant_constr ->
400330
"wildcard pattern given as argument to a constant constructor"
401-
| Eol_in_string ->
402-
"unescaped end-of-line in a string constant (non-portable code)"
403331
| Duplicate_definitions (kind, cname, tc1, tc2) ->
404332
Printf.sprintf "the %s %s is defined in both types %s and %s." kind cname
405333
tc1 tc2
@@ -446,18 +374,11 @@ let message = function
446374
kind s
447375
| Attribute_payload (a, s) ->
448376
Printf.sprintf "illegal payload for attribute '%s'.\n%s" a s
449-
| Eliminated_optional_arguments sl ->
450-
Printf.sprintf "implicit elimination of optional argument%s %s"
451-
(if List.length sl = 1 then "" else "s")
452-
(String.concat ", " sl)
453377
| No_cmi_file (name, None) ->
454378
"no cmi file was found in path for module " ^ name
455379
| No_cmi_file (name, Some msg) ->
456380
Printf.sprintf "no valid cmi file was found in path for module %s. %s" name
457381
msg
458-
| Bad_docstring unattached ->
459-
if unattached then "unattached documentation comment (ignored)"
460-
else "ambiguous documentation comment"
461382
| Fragile_literal_pattern ->
462383
Printf.sprintf
463384
"Code should not depend on the actual values of\n\
@@ -495,15 +416,8 @@ let message = function
495416
"Polymorphic comparison introduced (maybe unsafe)"
496417
| Bs_ffi_warning s -> "FFI warning: " ^ s
497418
| Bs_derive_warning s -> "@deriving warning: " ^ s
498-
| Bs_fragile_external s ->
499-
s
500-
^ " : using an empty string as a shorthand to infer the external's name \
501-
from the value's name is dangerous when refactoring, and therefore \
502-
deprecated"
503-
| Bs_unimplemented_primitive s -> "Unimplemented primitive used: " ^ s
504419
| Bs_integer_literal_overflow ->
505420
"Integer literal exceeds the range of representable integers of type int"
506-
| Bs_uninterpreted_delimiters s -> "Uninterpreted delimiters " ^ s
507421
| Bs_toplevel_expression_unit help ->
508422
Printf.sprintf
509423
"This%sis at the top level and is expected to return `unit`. But it's \
@@ -581,8 +495,6 @@ let check_fatal () =
581495

582496
let descriptions =
583497
[
584-
(1, "Suspicious-looking start-of-comment mark.");
585-
(2, "Suspicious-looking end-of-comment mark.");
586498
(3, "Deprecated feature.");
587499
( 4,
588500
"Fragile pattern matching: matching that will remain complete even\n\
@@ -591,18 +503,10 @@ let descriptions =
591503
( 5,
592504
"Partially applied function: expression whose result has function\n\
593505
\ type and is ignored." );
594-
(7, "Method overridden.");
595506
(8, "Partial match: missing cases in pattern-matching.");
596507
(9, "Missing fields in a record pattern.");
597-
( 10,
598-
"Expression on the left-hand side of a sequence that doesn't have type\n\
599-
\ \"unit\" (and that is not a function, see warning number 5)." );
600508
(11, "Redundant case in a pattern matching (unused match case).");
601509
(12, "Redundant sub-pattern in a pattern-matching.");
602-
(13, "Instance variable overridden.");
603-
(14, "Illegal backslash escape in a string constant.");
604-
(15, "Private method made public implicitly.");
605-
(16, "Unerasable optional argument.");
606510
(17, "Undeclared virtual method.");
607511
(18, "Non-principal type.");
608512
(19, "Type without principality.");
@@ -623,7 +527,6 @@ let descriptions =
623527
\ \"let\" nor \"as\", and doesn't start with an underscore (\"_\")\n\
624528
\ character." );
625529
(28, "Wildcard pattern given as argument to a constant constructor.");
626-
(29, "Unescaped end-of-line in a string constant (non-portable code).");
627530
( 30,
628531
"Two labels or constructors of the same name are defined in two\n\
629532
\ mutually recursive types." );
@@ -642,9 +545,7 @@ let descriptions =
642545
(45, "Open statement shadows an already defined label or constructor.");
643546
(46, "Error in environment variable.");
644547
(47, "Illegal attribute payload.");
645-
(48, "Implicit elimination of optional arguments.");
646548
(49, "Absent cmi file when looking up module alias.");
647-
(50, "Unexpected documentation comment.");
648549
(52, "Fragile constant pattern.");
649550
(53, "Attribute cannot appear in this context");
650551
(54, "Attribute used more than once on an expression");
@@ -658,14 +559,9 @@ let descriptions =
658559
(102, "Polymorphic comparison introduced (maybe unsafe)");
659560
(103, "Fragile FFI definitions");
660561
(104, "@deriving warning with customized message ");
661-
( 105,
662-
"External name is inferred from val name is unsafe from refactoring when \
663-
changing value name" );
664-
(106, "Unimplemented primitive used:");
665562
( 107,
666563
"Integer literal exceeds the range of representable integers of type int"
667564
);
668-
(108, "Uninterpreted delimiters (for unicode)");
669565
(109, "Toplevel expression has unit type");
670566
(110, "Todo found");
671567
]

compiler/ext/warnings.mli

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,13 @@ type loc = {
2222
type top_level_unit_help = FunctionCall | Other
2323

2424
type t =
25-
| Comment_start (* 1 *)
26-
| Comment_not_end (* 2 *)
2725
| Deprecated of string * loc * loc * bool (* 3 *)
2826
| Fragile_match of string (* 4 *)
2927
| Partial_application (* 5 *)
30-
| Method_override of string list (* 7 *)
3128
| Partial_match of string (* 8 *)
3229
| Non_closed_record_pattern of string (* 9 *)
33-
| Statement_type (* 10 *)
3430
| Unused_match (* 11 *)
3531
| Unused_pat (* 12 *)
36-
| Instance_variable_override of string list (* 13 *)
37-
| Illegal_backslash (* 14 *)
38-
| Implicit_public_methods of string list (* 15 *)
39-
| Unerasable_optional_argument (* 16 *)
4032
| Unused_argument (* 20 *)
4133
| Nonreturning_statement (* 21 *)
4234
| Preprocessor of string (* 22 *)
@@ -46,7 +38,6 @@ type t =
4638
| Unused_var of string (* 26 *)
4739
| Unused_var_strict of string (* 27 *)
4840
| Wildcard_arg_to_constant_constr (* 28 *)
49-
| Eol_in_string (* 29 *)
5041
| Duplicate_definitions of string * string * string * string (* 30 *)
5142
| Unused_value_declaration of string (* 32 *)
5243
| Unused_open of string (* 33 *)
@@ -60,9 +51,7 @@ type t =
6051
| Open_shadow_identifier of string * string (* 44 *)
6152
| Open_shadow_label_constructor of string * string (* 45 *)
6253
| Attribute_payload of string * string (* 47 *)
63-
| Eliminated_optional_arguments of string list (* 48 *)
6454
| No_cmi_file of string * string option (* 49 *)
65-
| Bad_docstring of bool (* 50 *)
6655
| Fragile_literal_pattern (* 52 *)
6756
| Misplaced_attribute of string (* 53 *)
6857
| Duplicated_attribute of string (* 54 *)
@@ -74,10 +63,7 @@ type t =
7463
| Bs_polymorphic_comparison (* 102 *)
7564
| Bs_ffi_warning of string (* 103 *)
7665
| Bs_derive_warning of string (* 104 *)
77-
| Bs_fragile_external of string (* 105 *)
78-
| Bs_unimplemented_primitive of string (* 106 *)
7966
| Bs_integer_literal_overflow (* 107 *)
80-
| Bs_uninterpreted_delimiters of string (* 108 *)
8167
| Bs_toplevel_expression_unit of
8268
(string * top_level_unit_help) option (* 109 *)
8369
| Bs_todo of string option (* 110 *)

compiler/frontend/ast_core_type.ml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,17 @@ let list_of_arrow (ty : t) : t * Parsetree.arg list =
136136
match ty.ptyp_desc with
137137
| Ptyp_arrow {arg; ret; arity} when arity = None || acc = [] ->
138138
aux ret (arg :: acc)
139-
| Ptyp_poly (_, ty) ->
140-
(* should not happen? *)
141-
Bs_syntaxerr.err ty.ptyp_loc Unhandled_poly_type
139+
| Ptyp_poly _ ->
140+
(* unreachable: [list_of_arrow] only recurses into an arrow's return
141+
(and is only ever called on an external's type annotation), so to get
142+
here a [Ptyp_poly] would have to sit in an external's arg/return
143+
position. The external type — and every arrow arg/return — is parsed
144+
by [parse_typ_expr], which never routes to [parse_poly_type_expr]; an
145+
inline `'a. …` there is a plain syntax error ("Did you forget a `=`").
146+
[Ptyp_poly] is produced only for record/object field types and
147+
signature `val` descriptions, and a field-nested poly is a non-arrow
148+
leaf that [list_of_arrow] stops at, never the recursed return. *)
149+
assert false
142150
| _ -> (ty, List.rev acc)
143151
in
144152
aux ty []

compiler/frontend/ast_utf8_string_interp.ml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ module Delim = struct
289289
let escaped_j_delimiter = "*j" (* not user level syntax allowed *)
290290
let escaped_back_quote_delimiter = "bq"
291291
let some_escaped_back_quote_delimiter = Some "bq"
292-
let unescaped_js_delimiter = "js"
293292
let some_escaped_j_delimiter = Some escaped_j_delimiter
294293
end
295294

@@ -339,6 +338,4 @@ let is_unicode_string opt =
339338
Ext_string.equal opt Delim.escaped_j_delimiter
340339
|| Ext_string.equal opt Delim.escaped_back_quote_delimiter
341340

342-
let is_unescaped s = Ext_string.equal s Delim.unescaped_js_delimiter
343-
344341
let parse_processed_delim = Delim.parse_processed

compiler/frontend/ast_utf8_string_interp.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,4 @@ val transform_exp :
5959
Parsetree.expression -> string -> string -> Parsetree.expression
6060
val transform_pat : Parsetree.pattern -> string -> string -> Parsetree.pattern
6161
val is_unicode_string : string -> bool
62-
val is_unescaped : string -> bool
6362
val parse_processed_delim : string option -> External_arg_spec.delim option

compiler/frontend/bs_ast_invariant.ml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ let super = Ast_iterator.default_iterator
5252

5353
let check_constant loc (const : Parsetree.constant) =
5454
match const with
55-
| Pconst_string (_, Some s) ->
56-
if Ast_utf8_string_interp.is_unescaped s then
57-
Bs_warnings.error_unescaped_delimiter loc s
5855
| Pconst_integer (s, None) -> (
5956
(* range check using int32
6057
It is better to give a warning instead of error to avoid make people unhappy.

0 commit comments

Comments
 (0)