Skip to content

Commit 746ff7c

Browse files
authored
Merge pull request #2183 from BuckleScript/expose_warning_message
clean up super_warning, it is also future proof when add more warning number
2 parents a4e899e + 441228c commit 746ff7c

File tree

5 files changed

+12
-278
lines changed

5 files changed

+12
-278
lines changed

jscomp/bin/bsdep.ml

+1
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,7 @@ val backup: unit -> state
14081408
val restore: state -> unit
14091409

14101410

1411+
val message : t -> string
14111412
val number: t -> int
14121413
val super_print : (t -> string) -> formatter -> t -> unit;;
14131414

jscomp/bin/bspp.ml

+1
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,7 @@ val backup: unit -> state
13451345
val restore: state -> unit
13461346

13471347

1348+
val message : t -> string
13481349
val number: t -> int
13491350
val super_print : (t -> string) -> formatter -> t -> unit;;
13501351

jscomp/bin/bsppx.ml

+1
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,7 @@ val backup: unit -> state
13451345
val restore: state -> unit
13461346

13471347

1348+
val message : t -> string
13481349
val number: t -> int
13491350
val super_print : (t -> string) -> formatter -> t -> unit;;
13501351

jscomp/bin/whole_compiler.ml

+5-139
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,7 @@ val backup: unit -> state
11771177
val restore: state -> unit
11781178

11791179

1180+
val message : t -> string
11801181
val number: t -> int
11811182
val super_print : (t -> string) -> formatter -> t -> unit;;
11821183

@@ -114619,160 +114620,25 @@ module Super_warnings
114619114620
let fprintf = Format.fprintf
114620114621
(* taken from https://github.com/BuckleScript/ocaml/blob/d4144647d1bf9bc7dc3aadc24c25a7efa3a67915/utils/warnings.ml#L251 *)
114621114622
(* actual modified message branches are commented *)
114622-
let message = Warnings.(function
114623-
| Comment_start -> "this is the start of a comment."
114624-
| Comment_not_end -> "this is not the end of a comment."
114623+
let message (warning : Warnings.t) =
114624+
match warning with
114625114625
| Deprecated s -> s ^ " is deprecated. "
114626-
| Fragile_match "" ->
114627-
"this pattern-matching is fragile."
114628-
| Fragile_match s ->
114629-
"this pattern-matching is fragile.\n\
114630-
It will remain exhaustive when constructors are added to type " ^ s ^ "."
114631-
| Partial_application ->
114632-
"this function application is partial,\n\
114633-
maybe some arguments are missing."
114634-
| Labels_omitted ->
114635-
"labels were omitted in the application of this function."
114636-
| Method_override [lab] ->
114637-
"the method " ^ lab ^ " is overridden."
114638-
| Method_override (cname :: slist) ->
114639-
String.concat " "
114640-
("the following methods are overridden by the class"
114641-
:: cname :: ":\n " :: slist)
114642-
| Method_override [] -> assert false
114643114626
| Partial_match "" ->
114644-
(* modified *)
114645114627
"You forgot to handle a possible value here, though we don't have more information on the value."
114646114628
| Partial_match s ->
114647-
(* modified *)
114648114629
"You forgot to handle a possible value here, for example: \n" ^ s
114649-
| Non_closed_record_pattern s ->
114650-
"the following labels are not bound in this record pattern:\n" ^ s ^
114651-
"\nEither bind these labels explicitly or add '; _' to the pattern."
114652-
| Statement_type ->
114653-
"this expression should have type unit."
114654-
| Unused_match -> "this match case is unused."
114655-
| Unused_pat -> "this sub-pattern is unused."
114656-
| Instance_variable_override [lab] ->
114657-
"the instance variable " ^ lab ^ " is overridden.\n" ^
114658-
"The behaviour changed in ocaml 3.10 (previous behaviour was hiding.)"
114659-
| Instance_variable_override (cname :: slist) ->
114660-
String.concat " "
114661-
("the following instance variables are overridden by the class"
114662-
:: cname :: ":\n " :: slist) ^
114663-
"\nThe behaviour changed in ocaml 3.10 (previous behaviour was hiding.)"
114664-
| Instance_variable_override [] -> assert false
114665-
| Illegal_backslash -> "illegal backslash escape in string."
114666-
| Implicit_public_methods l ->
114667-
"the following private methods were made public implicitly:\n "
114668-
^ String.concat " " l ^ "."
114669114630
| Unerasable_optional_argument ->
114670-
(* modified *)
114671-
(* TODO: better formatting *)
114672114631
String.concat "\n\n"
114673114632
["This is an optional argument at the final position of the function; omitting it while calling the function might be confused with currying. For example:";
114674114633
" let myTitle = displayTitle \"hello!\";";
114675114634
"if `displayTitle` accepts an optional argument at the final position, it'd be unclear whether `myTitle` is a curried function or the final result.";
114676114635
"Here's the language's rule: an optional argument is erased as soon as the 1st positional (i.e. neither labeled nor optional) argument defined after it is passed in.";
114677114636
"To solve this, you'd conventionally add an extra () argument at the end of the function declaration."]
114678-
| Undeclared_virtual_method m -> "the virtual method "^m^" is not declared."
114679-
| Not_principal s -> s^" is not principal."
114680-
| Without_principality s -> s^" without principality."
114681-
| Unused_argument -> "this argument will not be used by the function."
114682-
| Nonreturning_statement ->
114683-
"this statement never returns (or has an unsound type.)"
114684-
| Preprocessor s -> s
114685-
| Useless_record_with ->
114686-
"all the fields are explicitly listed in this record:\n\
114687-
the 'with' clause is useless."
114688114637
| Bad_module_name (modname) ->
114689-
(* modified *)
114690114638
"This file's name is potentially invalid. The build systems conventionally turn a file name into a module name by upper-casing the first letter. " ^ modname ^ " isn't a valid module name.\n" ^
114691114639
"Note: some build systems might e.g. turn kebab-case into CamelCase module, which is why this isn't a hard error."
114692-
| All_clauses_guarded ->
114693-
"bad style, all clauses in this pattern-matching are guarded."
114694-
| Unused_var v | Unused_var_strict v -> "unused variable " ^ v ^ "."
114695-
| Wildcard_arg_to_constant_constr ->
114696-
"wildcard pattern given as argument to a constant constructor"
114697-
| Eol_in_string ->
114698-
"unescaped end-of-line in a string constant (non-portable code)"
114699-
| Duplicate_definitions (kind, cname, tc1, tc2) ->
114700-
Printf.sprintf "the %s %s is defined in both types %s and %s."
114701-
kind cname tc1 tc2
114702-
| Multiple_definition(modname, file1, file2) ->
114703-
Printf.sprintf
114704-
"files %s and %s both define a module named %s"
114705-
file1 file2 modname
114706-
| Unused_value_declaration v -> "unused value " ^ v ^ "."
114707-
| Unused_open s -> "unused open " ^ s ^ "."
114708-
| Unused_type_declaration s -> "unused type " ^ s ^ "."
114709-
| Unused_for_index s -> "unused for-loop index " ^ s ^ "."
114710-
| Unused_ancestor s -> "unused ancestor variable " ^ s ^ "."
114711-
| Unused_constructor (s, false, false) -> "unused constructor " ^ s ^ "."
114712-
| Unused_constructor (s, true, _) ->
114713-
"constructor " ^ s ^
114714-
" is never used to build values.\n\
114715-
(However, this constructor appears in patterns.)"
114716-
| Unused_constructor (s, false, true) ->
114717-
"constructor " ^ s ^
114718-
" is never used to build values.\n\
114719-
Its type is exported as a private type."
114720-
| Unused_extension (s, false, false) ->
114721-
"unused extension constructor " ^ s ^ "."
114722-
| Unused_extension (s, true, _) ->
114723-
"extension constructor " ^ s ^
114724-
" is never used to build values.\n\
114725-
(However, this constructor appears in patterns.)"
114726-
| Unused_extension (s, false, true) ->
114727-
"extension constructor " ^ s ^
114728-
" is never used to build values.\n\
114729-
It is exported or rebound as a private extension."
114730-
| Unused_rec_flag ->
114731-
"unused rec flag."
114732-
| Name_out_of_scope (ty, [nm], false) ->
114733-
nm ^ " was selected from type " ^ ty ^
114734-
".\nIt is not visible in the current scope, and will not \n\
114735-
be selected if the type becomes unknown."
114736-
| Name_out_of_scope (_, _, false) -> assert false
114737-
| Name_out_of_scope (ty, slist, true) ->
114738-
"this record of type "^ ty ^" contains fields that are \n\
114739-
not visible in the current scope: "
114740-
^ String.concat " " slist ^ ".\n\
114741-
They will not be selected if the type becomes unknown."
114742-
| Ambiguous_name ([s], tl, false) ->
114743-
s ^ " belongs to several types: " ^ String.concat " " tl ^
114744-
"\nThe first one was selected. Please disambiguate if this is wrong."
114745-
| Ambiguous_name (_, _, false) -> assert false
114746-
| Ambiguous_name (slist, tl, true) ->
114747-
"these field labels belong to several types: " ^
114748-
String.concat " " tl ^
114749-
"\nThe first one was selected. Please disambiguate if this is wrong."
114750-
| Disambiguated_name s ->
114751-
"this use of " ^ s ^ " required disambiguation."
114752-
| Nonoptional_label s ->
114753-
"the label " ^ s ^ " is not optional."
114754-
| Open_shadow_identifier (kind, s) ->
114755-
Printf.sprintf
114756-
"this open statement shadows the %s identifier %s (which is later used)"
114757-
kind s
114758-
| Open_shadow_label_constructor (kind, s) ->
114759-
Printf.sprintf
114760-
"this open statement shadows the %s %s (which is later used)"
114761-
kind s
114762-
| Bad_env_variable (var, s) ->
114763-
Printf.sprintf "illegal environment variable %s : %s" var s
114764-
| Attribute_payload (a, s) ->
114765-
Printf.sprintf "illegal payload for attribute '%s'.\n%s" a s
114766-
| Eliminated_optional_arguments sl ->
114767-
Printf.sprintf "implicit elimination of optional argument%s %s"
114768-
(if List.length sl = 1 then "" else "s")
114769-
(String.concat ", " sl)
114770-
| No_cmi_file s ->
114771-
"no cmi file was found in path for module " ^ s
114772-
| Bad_docstring unattached ->
114773-
if unattached then "unattached documentation comment (ignored)"
114774-
else "ambiguous documentation comment"
114775-
);;
114640+
| _ -> Warnings.message warning
114641+
;;
114776114642

114777114643
end
114778114644
module Super_location

jscomp/super_errors/super_warnings.ml

+4-139
Original file line numberDiff line numberDiff line change
@@ -1,157 +1,22 @@
11
let fprintf = Format.fprintf
22
(* taken from https://github.com/BuckleScript/ocaml/blob/d4144647d1bf9bc7dc3aadc24c25a7efa3a67915/utils/warnings.ml#L251 *)
33
(* actual modified message branches are commented *)
4-
let message = Warnings.(function
5-
| Comment_start -> "this is the start of a comment."
6-
| Comment_not_end -> "this is not the end of a comment."
4+
let message (warning : Warnings.t) =
5+
match warning with
76
| Deprecated s -> s ^ " is deprecated. "
8-
| Fragile_match "" ->
9-
"this pattern-matching is fragile."
10-
| Fragile_match s ->
11-
"this pattern-matching is fragile.\n\
12-
It will remain exhaustive when constructors are added to type " ^ s ^ "."
13-
| Partial_application ->
14-
"this function application is partial,\n\
15-
maybe some arguments are missing."
16-
| Labels_omitted ->
17-
"labels were omitted in the application of this function."
18-
| Method_override [lab] ->
19-
"the method " ^ lab ^ " is overridden."
20-
| Method_override (cname :: slist) ->
21-
String.concat " "
22-
("the following methods are overridden by the class"
23-
:: cname :: ":\n " :: slist)
24-
| Method_override [] -> assert false
257
| Partial_match "" ->
26-
(* modified *)
278
"You forgot to handle a possible value here, though we don't have more information on the value."
289
| Partial_match s ->
29-
(* modified *)
3010
"You forgot to handle a possible value here, for example: \n" ^ s
31-
| Non_closed_record_pattern s ->
32-
"the following labels are not bound in this record pattern:\n" ^ s ^
33-
"\nEither bind these labels explicitly or add '; _' to the pattern."
34-
| Statement_type ->
35-
"this expression should have type unit."
36-
| Unused_match -> "this match case is unused."
37-
| Unused_pat -> "this sub-pattern is unused."
38-
| Instance_variable_override [lab] ->
39-
"the instance variable " ^ lab ^ " is overridden.\n" ^
40-
"The behaviour changed in ocaml 3.10 (previous behaviour was hiding.)"
41-
| Instance_variable_override (cname :: slist) ->
42-
String.concat " "
43-
("the following instance variables are overridden by the class"
44-
:: cname :: ":\n " :: slist) ^
45-
"\nThe behaviour changed in ocaml 3.10 (previous behaviour was hiding.)"
46-
| Instance_variable_override [] -> assert false
47-
| Illegal_backslash -> "illegal backslash escape in string."
48-
| Implicit_public_methods l ->
49-
"the following private methods were made public implicitly:\n "
50-
^ String.concat " " l ^ "."
5111
| Unerasable_optional_argument ->
52-
(* modified *)
53-
(* TODO: better formatting *)
5412
String.concat "\n\n"
5513
["This is an optional argument at the final position of the function; omitting it while calling the function might be confused with currying. For example:";
5614
" let myTitle = displayTitle \"hello!\";";
5715
"if `displayTitle` accepts an optional argument at the final position, it'd be unclear whether `myTitle` is a curried function or the final result.";
5816
"Here's the language's rule: an optional argument is erased as soon as the 1st positional (i.e. neither labeled nor optional) argument defined after it is passed in.";
5917
"To solve this, you'd conventionally add an extra () argument at the end of the function declaration."]
60-
| Undeclared_virtual_method m -> "the virtual method "^m^" is not declared."
61-
| Not_principal s -> s^" is not principal."
62-
| Without_principality s -> s^" without principality."
63-
| Unused_argument -> "this argument will not be used by the function."
64-
| Nonreturning_statement ->
65-
"this statement never returns (or has an unsound type.)"
66-
| Preprocessor s -> s
67-
| Useless_record_with ->
68-
"all the fields are explicitly listed in this record:\n\
69-
the 'with' clause is useless."
7018
| Bad_module_name (modname) ->
71-
(* modified *)
7219
"This file's name is potentially invalid. The build systems conventionally turn a file name into a module name by upper-casing the first letter. " ^ modname ^ " isn't a valid module name.\n" ^
7320
"Note: some build systems might e.g. turn kebab-case into CamelCase module, which is why this isn't a hard error."
74-
| All_clauses_guarded ->
75-
"bad style, all clauses in this pattern-matching are guarded."
76-
| Unused_var v | Unused_var_strict v -> "unused variable " ^ v ^ "."
77-
| Wildcard_arg_to_constant_constr ->
78-
"wildcard pattern given as argument to a constant constructor"
79-
| Eol_in_string ->
80-
"unescaped end-of-line in a string constant (non-portable code)"
81-
| Duplicate_definitions (kind, cname, tc1, tc2) ->
82-
Printf.sprintf "the %s %s is defined in both types %s and %s."
83-
kind cname tc1 tc2
84-
| Multiple_definition(modname, file1, file2) ->
85-
Printf.sprintf
86-
"files %s and %s both define a module named %s"
87-
file1 file2 modname
88-
| Unused_value_declaration v -> "unused value " ^ v ^ "."
89-
| Unused_open s -> "unused open " ^ s ^ "."
90-
| Unused_type_declaration s -> "unused type " ^ s ^ "."
91-
| Unused_for_index s -> "unused for-loop index " ^ s ^ "."
92-
| Unused_ancestor s -> "unused ancestor variable " ^ s ^ "."
93-
| Unused_constructor (s, false, false) -> "unused constructor " ^ s ^ "."
94-
| Unused_constructor (s, true, _) ->
95-
"constructor " ^ s ^
96-
" is never used to build values.\n\
97-
(However, this constructor appears in patterns.)"
98-
| Unused_constructor (s, false, true) ->
99-
"constructor " ^ s ^
100-
" is never used to build values.\n\
101-
Its type is exported as a private type."
102-
| Unused_extension (s, false, false) ->
103-
"unused extension constructor " ^ s ^ "."
104-
| Unused_extension (s, true, _) ->
105-
"extension constructor " ^ s ^
106-
" is never used to build values.\n\
107-
(However, this constructor appears in patterns.)"
108-
| Unused_extension (s, false, true) ->
109-
"extension constructor " ^ s ^
110-
" is never used to build values.\n\
111-
It is exported or rebound as a private extension."
112-
| Unused_rec_flag ->
113-
"unused rec flag."
114-
| Name_out_of_scope (ty, [nm], false) ->
115-
nm ^ " was selected from type " ^ ty ^
116-
".\nIt is not visible in the current scope, and will not \n\
117-
be selected if the type becomes unknown."
118-
| Name_out_of_scope (_, _, false) -> assert false
119-
| Name_out_of_scope (ty, slist, true) ->
120-
"this record of type "^ ty ^" contains fields that are \n\
121-
not visible in the current scope: "
122-
^ String.concat " " slist ^ ".\n\
123-
They will not be selected if the type becomes unknown."
124-
| Ambiguous_name ([s], tl, false) ->
125-
s ^ " belongs to several types: " ^ String.concat " " tl ^
126-
"\nThe first one was selected. Please disambiguate if this is wrong."
127-
| Ambiguous_name (_, _, false) -> assert false
128-
| Ambiguous_name (slist, tl, true) ->
129-
"these field labels belong to several types: " ^
130-
String.concat " " tl ^
131-
"\nThe first one was selected. Please disambiguate if this is wrong."
132-
| Disambiguated_name s ->
133-
"this use of " ^ s ^ " required disambiguation."
134-
| Nonoptional_label s ->
135-
"the label " ^ s ^ " is not optional."
136-
| Open_shadow_identifier (kind, s) ->
137-
Printf.sprintf
138-
"this open statement shadows the %s identifier %s (which is later used)"
139-
kind s
140-
| Open_shadow_label_constructor (kind, s) ->
141-
Printf.sprintf
142-
"this open statement shadows the %s %s (which is later used)"
143-
kind s
144-
| Bad_env_variable (var, s) ->
145-
Printf.sprintf "illegal environment variable %s : %s" var s
146-
| Attribute_payload (a, s) ->
147-
Printf.sprintf "illegal payload for attribute '%s'.\n%s" a s
148-
| Eliminated_optional_arguments sl ->
149-
Printf.sprintf "implicit elimination of optional argument%s %s"
150-
(if List.length sl = 1 then "" else "s")
151-
(String.concat ", " sl)
152-
| No_cmi_file s ->
153-
"no cmi file was found in path for module " ^ s
154-
| Bad_docstring unattached ->
155-
if unattached then "unattached documentation comment (ignored)"
156-
else "ambiguous documentation comment"
157-
);;
21+
| _ -> Warnings.message warning
22+
;;

0 commit comments

Comments
 (0)