Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions compiler/common/bs_warnings.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,3 @@

let warn_literal_overflow loc =
Location.prerr_warning loc Bs_integer_literal_overflow

let error_unescaped_delimiter loc txt =
Location.prerr_warning loc (Bs_uninterpreted_delimiters txt)
2 changes: 0 additions & 2 deletions compiler/common/bs_warnings.mli
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,3 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

val warn_literal_overflow : Location.t -> unit

val error_unescaped_delimiter : Location.t -> string -> unit
104 changes: 0 additions & 104 deletions compiler/ext/warnings.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,13 @@ type loc = {
type top_level_unit_help = FunctionCall | Other

type t =
| Comment_start (* 1 *)
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verification: no raise site (G). rg 'prerr_warning.*Comment_start|Warnings.Comment_start' outside warnings.ml returns zero results. Lexer-era warning from OCaml; ReScript's modern parser doesn't emit it.

| Comment_not_end (* 2 *)
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verification: no raise site (G). Same as Comment_start — rg outside warnings.ml returns zero. Lexer-era warning, not emitted by the modern parser.

| Deprecated of string * loc * loc * bool (* 3 *)
| Fragile_match of string (* 4 *)
| Partial_application (* 5 *)
| Method_override of string list (* 7 *)
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verification: no raise site (G). OCaml class-system warning — rg outside warnings.ml returns zero. ReScript doesn't expose class/method overrides, so the warning has no possible trigger surface.

| Partial_match of string (* 8 *)
| Non_closed_record_pattern of string (* 9 *)
| Statement_type (* 10 *)
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verification: guarded — only caller passes statement=false (S). Raised at typecore.ml:2052 inside check_application_result, gated by if statement then prerr_warning Statement_type. The only call site (typecore.ml:3983 in master) is check_application_result env false exp with statement = false, so the guarded branch never fires. The dead-removal drops the statement parameter, the call site's false, and the guarded branch in one consistent step.

| Unused_match (* 11 *)
| Unused_pat (* 12 *)
| Instance_variable_override of string list (* 13 *)
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verification: no raise site (G). OCaml class-system warning. rg outside warnings.ml returns zero.

| Illegal_backslash (* 14 *)
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verification: no raise site (G). Lexer-era escape warning. rg outside warnings.ml returns zero — ReScript's scanner validates escapes inline at parse time.

| Implicit_public_methods of string list (* 15 *)
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verification: no raise site (G). OCaml class-system warning. rg outside warnings.ml returns zero.

| Unerasable_optional_argument (* 16 *)
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verification: disabled within the only firing window (S). Raised at typecore.ml:3526 inside type_function for is_optional l && not_function env ty_res. type_function (lines 3475–3479 in master) calls Warnings.parse_options false ("-" ^ string_of_int (Warnings.number Unerasable_optional_argument)) immediately before the check runs, disabling warning 16 for the entire function-typing block (Warnings.restore state re-enables after). No path can fire warning 16 while the disable is in effect. The dead-removal drops the disable, the not_function check, and the prerr_warning call together.

| Unused_argument (* 20 *)
| Nonreturning_statement (* 21 *)
| Preprocessor of string (* 22 *)
Expand All @@ -53,7 +45,6 @@ type t =
| Unused_var of string (* 26 *)
| Unused_var_strict of string (* 27 *)
| Wildcard_arg_to_constant_constr (* 28 *)
| Eol_in_string (* 29 *)
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verification: no raise site (G). Lexer-level string warning. rg outside warnings.ml returns zero.

| Duplicate_definitions of string * string * string * string (*30 *)
| Unused_value_declaration of string (* 32 *)
| Unused_open of string (* 33 *)
Expand All @@ -67,9 +58,7 @@ type t =
| Open_shadow_identifier of string * string (* 44 *)
| Open_shadow_label_constructor of string * string (* 45 *)
| Attribute_payload of string * string (* 47 *)
| Eliminated_optional_arguments of string list (* 48 *)
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verification: no raise site (G). Declared but never raised. rg 'prerr_warning.*Eliminated_optional_arguments' returns zero matches under compiler/.

| No_cmi_file of string * string option (* 49 *)
| Bad_docstring of bool (* 50 *)
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verification: no raise site (G). Declared but never raised. rg returns zero matches outside warnings.ml. Also default-disabled in bsc_warnings.ml.

| Fragile_literal_pattern (* 52 *)
| Misplaced_attribute of string (* 53 *)
| Duplicated_attribute of string (* 54 *)
Expand All @@ -81,10 +70,7 @@ type t =
| Bs_polymorphic_comparison (* 102 *)
| Bs_ffi_warning of string (* 103 *)
| Bs_derive_warning of string (* 104 *)
| Bs_fragile_external of string (* 105 *)
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verification: no raise site (G). Declared but never raised. rg returns zero matches outside warnings.ml.

| Bs_unimplemented_primitive of string (* 106 *)
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verification: no raise site (G). Declared but never raised. rg returns zero matches outside warnings.ml.

| Bs_integer_literal_overflow (* 107 *)
| Bs_uninterpreted_delimiters of string (* 108 *)
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verification: PPX rewrites the trigger AST (S). Raised at bs_warnings.ml:29 for Pconst_string (_, Some "js"). The parser does emit Some "js" for all strings in ParseForTypeChecker mode (res_core.ml:1066), but the builtin PPX runs first: Bs_builtin_ppx.mapper calls Ast_utf8_string_interp.transform_exp which replaces Some "js" with Some "j" (escaped) or Some "*j" (backtick) before Bs_ast_invariant.check_constant ever sees the constant. With -bs-no-builtin-ppx, the warning iterator is skipped entirely (ppx_entry.ml:58–62). Either way the warning never fires for a real ReScript source program.

| Bs_toplevel_expression_unit of
(string * top_level_unit_help) option (* 109 *)
| Bs_todo of string option (* 110 *)
Expand All @@ -96,21 +82,13 @@ type t =
*)

let number = function
| Comment_start -> 1
| Comment_not_end -> 2
| Deprecated _ -> 3
| Fragile_match _ -> 4
| Partial_application -> 5
| Method_override _ -> 7
| Partial_match _ -> 8
| Non_closed_record_pattern _ -> 9
| Statement_type -> 10
| Unused_match -> 11
| Unused_pat -> 12
| Instance_variable_override _ -> 13
| Illegal_backslash -> 14
| Implicit_public_methods _ -> 15
| Unerasable_optional_argument -> 16
| Unused_argument -> 20
| Nonreturning_statement -> 21
| Preprocessor _ -> 22
Expand All @@ -120,7 +98,6 @@ let number = function
| Unused_var _ -> 26
| Unused_var_strict _ -> 27
| Wildcard_arg_to_constant_constr -> 28
| Eol_in_string -> 29
| Duplicate_definitions _ -> 30
| Unused_value_declaration _ -> 32
| Unused_open _ -> 33
Expand All @@ -134,9 +111,7 @@ let number = function
| Open_shadow_identifier _ -> 44
| Open_shadow_label_constructor _ -> 45
| Attribute_payload _ -> 47
| Eliminated_optional_arguments _ -> 48
| No_cmi_file _ -> 49
| Bad_docstring _ -> 50
| Fragile_literal_pattern -> 52
| Misplaced_attribute _ -> 53
| Duplicated_attribute _ -> 54
Expand All @@ -148,10 +123,7 @@ let number = function
| Bs_polymorphic_comparison -> 102
| Bs_ffi_warning _ -> 103
| Bs_derive_warning _ -> 104
| Bs_fragile_external _ -> 105
| Bs_unimplemented_primitive _ -> 106
| Bs_integer_literal_overflow -> 107
| Bs_uninterpreted_delimiters _ -> 108
| Bs_toplevel_expression_unit _ -> 109
| Bs_todo _ -> 110

Expand Down Expand Up @@ -297,8 +269,6 @@ let reset () =
let () = reset ()

let message = function
| Comment_start -> "this is the start of a comment."
| Comment_not_end -> "this is not the end of a comment."
| Deprecated (s, _, _, can_be_automigrated) ->
(* Reduce \r\n to \n:
- Prevents any \r characters being printed on Unix when processing
Expand All @@ -321,12 +291,6 @@ let message = function
It will remain exhaustive when constructors are added to type " ^ s ^ "."
| Partial_application ->
"this function application is partial,\nmaybe some arguments are missing."
| Method_override [lab] -> "the method " ^ lab ^ " is overridden."
| Method_override (cname :: slist) ->
String.concat " "
("the following methods are overridden by the class" :: cname :: ":\n "
:: slist)
| Method_override [] -> assert false
| Partial_match "" ->
"You forgot to handle a possible case here, though we don't have more \
information on the value."
Expand All @@ -335,42 +299,8 @@ let message = function
| Non_closed_record_pattern s ->
"the following labels are not bound in this record pattern: " ^ s
^ "\nEither bind these labels explicitly or add ', _' to the pattern."
| Statement_type ->
"This expression returns a value, but you're not doing anything with it. \
If this is on purpose, wrap it with `ignore`."
| Unused_match -> "this match case is unused."
| Unused_pat -> "this sub-pattern is unused."
| Instance_variable_override [lab] ->
"the instance variable " ^ lab ^ " is overridden.\n"
^ "The behaviour changed in ocaml 3.10 (previous behaviour was hiding.)"
| Instance_variable_override (cname :: slist) ->
String.concat " "
("the following instance variables are overridden by the class" :: cname
:: ":\n " :: slist)
^ "\nThe behaviour changed in ocaml 3.10 (previous behaviour was hiding.)"
| Instance_variable_override [] -> assert false
| Illegal_backslash -> "illegal backslash escape in string."
| Implicit_public_methods l ->
"the following private methods were made public implicitly:\n "
^ String.concat " " l ^ "."
| Unerasable_optional_argument ->
String.concat ""
[
"This optional parameter in final position will, in practice, not be \
optional.\n";
" Reorder the parameters so that at least one non-optional one is in \
final position or, if all parameters are optional, insert a final \
().\n\n";
" Explanation: If the final parameter is optional, it'd be unclear \
whether a function application that omits it should be considered \
fully applied, or partially applied. Imagine writing `let title = \
display(\"hello!\")`, only to realize `title` isn't your desired \
result, but a curried call that takes a final optional argument, e.g. \
`~showDate`.\n\n";
" Formal rule: an optional argument is considered intentionally \
omitted when the 1st positional (i.e. neither labeled nor optional) \
argument defined after it is passed in.";
]
| Unused_argument -> "this argument will not be used by the function."
| Nonreturning_statement ->
"This statement does not continue execution; following code is unreachable."
Expand Down Expand Up @@ -398,8 +328,6 @@ let message = function
v v
| Wildcard_arg_to_constant_constr ->
"wildcard pattern given as argument to a constant constructor"
| Eol_in_string ->
"unescaped end-of-line in a string constant (non-portable code)"
| Duplicate_definitions (kind, cname, tc1, tc2) ->
Printf.sprintf "the %s %s is defined in both types %s and %s." kind cname
tc1 tc2
Expand Down Expand Up @@ -446,18 +374,11 @@ let message = function
kind s
| Attribute_payload (a, s) ->
Printf.sprintf "illegal payload for attribute '%s'.\n%s" a s
| Eliminated_optional_arguments sl ->
Printf.sprintf "implicit elimination of optional argument%s %s"
(if List.length sl = 1 then "" else "s")
(String.concat ", " sl)
| No_cmi_file (name, None) ->
"no cmi file was found in path for module " ^ name
| No_cmi_file (name, Some msg) ->
Printf.sprintf "no valid cmi file was found in path for module %s. %s" name
msg
| Bad_docstring unattached ->
if unattached then "unattached documentation comment (ignored)"
else "ambiguous documentation comment"
| Fragile_literal_pattern ->
Printf.sprintf
"Code should not depend on the actual values of\n\
Expand Down Expand Up @@ -495,15 +416,8 @@ let message = function
"Polymorphic comparison introduced (maybe unsafe)"
| Bs_ffi_warning s -> "FFI warning: " ^ s
| Bs_derive_warning s -> "@deriving warning: " ^ s
| Bs_fragile_external s ->
s
^ " : using an empty string as a shorthand to infer the external's name \
from the value's name is dangerous when refactoring, and therefore \
deprecated"
| Bs_unimplemented_primitive s -> "Unimplemented primitive used: " ^ s
| Bs_integer_literal_overflow ->
"Integer literal exceeds the range of representable integers of type int"
| Bs_uninterpreted_delimiters s -> "Uninterpreted delimiters " ^ s
| Bs_toplevel_expression_unit help ->
Printf.sprintf
"This%sis at the top level and is expected to return `unit`. But it's \
Expand Down Expand Up @@ -581,8 +495,6 @@ let check_fatal () =

let descriptions =
[
(1, "Suspicious-looking start-of-comment mark.");
(2, "Suspicious-looking end-of-comment mark.");
(3, "Deprecated feature.");
( 4,
"Fragile pattern matching: matching that will remain complete even\n\
Expand All @@ -591,18 +503,10 @@ let descriptions =
( 5,
"Partially applied function: expression whose result has function\n\
\ type and is ignored." );
(7, "Method overridden.");
(8, "Partial match: missing cases in pattern-matching.");
(9, "Missing fields in a record pattern.");
( 10,
"Expression on the left-hand side of a sequence that doesn't have type\n\
\ \"unit\" (and that is not a function, see warning number 5)." );
(11, "Redundant case in a pattern matching (unused match case).");
(12, "Redundant sub-pattern in a pattern-matching.");
(13, "Instance variable overridden.");
(14, "Illegal backslash escape in a string constant.");
(15, "Private method made public implicitly.");
(16, "Unerasable optional argument.");
(17, "Undeclared virtual method.");
(18, "Non-principal type.");
(19, "Type without principality.");
Expand All @@ -623,7 +527,6 @@ let descriptions =
\ \"let\" nor \"as\", and doesn't start with an underscore (\"_\")\n\
\ character." );
(28, "Wildcard pattern given as argument to a constant constructor.");
(29, "Unescaped end-of-line in a string constant (non-portable code).");
( 30,
"Two labels or constructors of the same name are defined in two\n\
\ mutually recursive types." );
Expand All @@ -642,9 +545,7 @@ let descriptions =
(45, "Open statement shadows an already defined label or constructor.");
(46, "Error in environment variable.");
(47, "Illegal attribute payload.");
(48, "Implicit elimination of optional arguments.");
(49, "Absent cmi file when looking up module alias.");
(50, "Unexpected documentation comment.");
(52, "Fragile constant pattern.");
(53, "Attribute cannot appear in this context");
(54, "Attribute used more than once on an expression");
Expand All @@ -658,14 +559,9 @@ let descriptions =
(102, "Polymorphic comparison introduced (maybe unsafe)");
(103, "Fragile FFI definitions");
(104, "@deriving warning with customized message ");
( 105,
"External name is inferred from val name is unsafe from refactoring when \
changing value name" );
(106, "Unimplemented primitive used:");
( 107,
"Integer literal exceeds the range of representable integers of type int"
);
(108, "Uninterpreted delimiters (for unicode)");
(109, "Toplevel expression has unit type");
(110, "Todo found");
]
Expand Down
14 changes: 0 additions & 14 deletions compiler/ext/warnings.mli
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,13 @@ type loc = {
type top_level_unit_help = FunctionCall | Other

type t =
| Comment_start (* 1 *)
| Comment_not_end (* 2 *)
| Deprecated of string * loc * loc * bool (* 3 *)
| Fragile_match of string (* 4 *)
| Partial_application (* 5 *)
| Method_override of string list (* 7 *)
| Partial_match of string (* 8 *)
| Non_closed_record_pattern of string (* 9 *)
| Statement_type (* 10 *)
| Unused_match (* 11 *)
| Unused_pat (* 12 *)
| Instance_variable_override of string list (* 13 *)
| Illegal_backslash (* 14 *)
| Implicit_public_methods of string list (* 15 *)
| Unerasable_optional_argument (* 16 *)
| Unused_argument (* 20 *)
| Nonreturning_statement (* 21 *)
| Preprocessor of string (* 22 *)
Expand All @@ -46,7 +38,6 @@ type t =
| Unused_var of string (* 26 *)
| Unused_var_strict of string (* 27 *)
| Wildcard_arg_to_constant_constr (* 28 *)
| Eol_in_string (* 29 *)
| Duplicate_definitions of string * string * string * string (* 30 *)
| Unused_value_declaration of string (* 32 *)
| Unused_open of string (* 33 *)
Expand All @@ -60,9 +51,7 @@ type t =
| Open_shadow_identifier of string * string (* 44 *)
| Open_shadow_label_constructor of string * string (* 45 *)
| Attribute_payload of string * string (* 47 *)
| Eliminated_optional_arguments of string list (* 48 *)
| No_cmi_file of string * string option (* 49 *)
| Bad_docstring of bool (* 50 *)
| Fragile_literal_pattern (* 52 *)
| Misplaced_attribute of string (* 53 *)
| Duplicated_attribute of string (* 54 *)
Expand All @@ -74,10 +63,7 @@ type t =
| Bs_polymorphic_comparison (* 102 *)
| Bs_ffi_warning of string (* 103 *)
| Bs_derive_warning of string (* 104 *)
| Bs_fragile_external of string (* 105 *)
| Bs_unimplemented_primitive of string (* 106 *)
| Bs_integer_literal_overflow (* 107 *)
| Bs_uninterpreted_delimiters of string (* 108 *)
| Bs_toplevel_expression_unit of
(string * top_level_unit_help) option (* 109 *)
| Bs_todo of string option (* 110 *)
Expand Down
9 changes: 6 additions & 3 deletions compiler/frontend/ast_core_type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,12 @@ let list_of_arrow (ty : t) : t * Parsetree.arg list =
match ty.ptyp_desc with
| Ptyp_arrow {arg; ret; arity} when arity = None || acc = [] ->
aux ret (arg :: acc)
| Ptyp_poly (_, ty) ->
(* should not happen? *)
Bs_syntaxerr.err ty.ptyp_loc Unhandled_poly_type
| Ptyp_poly _ ->
(* unreachable: this would require an inline Ptyp_poly inside an
external's arrow chain. The ReScript parser misreads inline `'a.`
prefix syntax as the deprecated uncurried `(. …)` form and rejects
it, so the typer never sees the required AST shape. *)
assert false
| _ -> (ty, List.rev acc)
in
aux ty []
Expand Down
3 changes: 0 additions & 3 deletions compiler/frontend/ast_utf8_string_interp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ module Delim = struct
let escaped_j_delimiter = "*j" (* not user level syntax allowed *)
let escaped_back_quote_delimiter = "bq"
let some_escaped_back_quote_delimiter = Some "bq"
let unescaped_js_delimiter = "js"
let some_escaped_j_delimiter = Some escaped_j_delimiter
end

Expand Down Expand Up @@ -339,6 +338,4 @@ let is_unicode_string opt =
Ext_string.equal opt Delim.escaped_j_delimiter
|| Ext_string.equal opt Delim.escaped_back_quote_delimiter

let is_unescaped s = Ext_string.equal s Delim.unescaped_js_delimiter

let parse_processed_delim = Delim.parse_processed
1 change: 0 additions & 1 deletion compiler/frontend/ast_utf8_string_interp.mli
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,4 @@ val transform_exp :
Parsetree.expression -> string -> string -> Parsetree.expression
val transform_pat : Parsetree.pattern -> string -> string -> Parsetree.pattern
val is_unicode_string : string -> bool
val is_unescaped : string -> bool
val parse_processed_delim : string option -> External_arg_spec.delim option
3 changes: 0 additions & 3 deletions compiler/frontend/bs_ast_invariant.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ let super = Ast_iterator.default_iterator

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