Skip to content

Commit 57782f9

Browse files
authored
Merge pull request #4709 from chenglou/rm-react
[Super errors] Remove old ReasonReact diagnostics
2 parents 1073061 + 137b92e commit 57782f9

File tree

11 files changed

+224
-993
lines changed

11 files changed

+224
-993
lines changed

jscomp/super_errors/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Hello! This is the subdirectory for the new, newcomer-friendly OCaml/Reason warning & error report system. Most of the logic are lifted from the compiler (https://github.com/rescript-lang/ocaml/tree/master). The convention here is to have a `super_foo` for each corresponding compiler's file `foo`. So, for example, `warnings.ml` becomes `super_warnings.ml`. The exception is `super_main`, the entry point, and `super_reason_react`, our special handling of [ReasonReact](https://reasonml.github.io/reason-react/) errors.
1+
Hello! This is the subdirectory for the new, newcomer-friendly OCaml/Reason warning & error report system. Most of the logic are lifted from the compiler (https://github.com/rescript-lang/ocaml/tree/master). The convention here is to have a `super_foo` for each corresponding compiler's file `foo`. So, for example, `warnings.ml` becomes `super_warnings.ml`. The exception is `super_main`, the entry point.
22

33
Feel free to submit new ones or tweak existing messages in these files! They also have more precise comments in them that tells you how they work.
44

jscomp/super_errors/super_reason_react.ml

Lines changed: 0 additions & 119 deletions
This file was deleted.

jscomp/super_errors/super_reason_react.mli

Lines changed: 0 additions & 14 deletions
This file was deleted.

jscomp/super_errors/super_typecore.ml

Lines changed: 49 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -70,73 +70,59 @@ let rec collect_missing_arguments env type1 type2 = match type1 with
7070
end
7171
| _ -> None
7272

73-
let print_expr_type_clash env trace ppf =
74-
(* this is the most frequent error. Do whatever we can to provide specific
75-
guidance to this generic error before giving up *)
76-
if Super_reason_react.state_escape_scope trace && Super_reason_react.trace_both_component_spec trace then
77-
fprintf ppf "@[<v>\
78-
@[@{<info>Is this a ReasonReact reducerComponent or component with retained props?@}@ \
79-
If so, is the type for state, retained props or action declared _after_@ the component declaration?@ \
80-
@{<info>Moving these types above the component declaration@} should resolve this!@]\
81-
@]"
82-
(* This one above shouldn't catch any false positives, so we can safely not display the original type clash error. *)
83-
else if Super_reason_react.is_component_spec_wanted_react_element trace then
84-
fprintf ppf "@[<v>\
85-
@[@{<info>Did you want to create a ReasonReact element without using JSX?@}@ If not, disregard this.@ \
86-
If so, don't forget to wrap this value in `ReasonReact.element` yourself:@ https://reasonml.github.io/reason-react/docs/en/jsx.html#capitalized@]@,@,\
87-
@[@{<info>Here's the original error message@}@]@,\
88-
@]";
89-
begin
90-
let bottom_aliases_result = bottom_aliases trace in
91-
let missing_arguments = match bottom_aliases_result with
92-
| Some (actual, expected) -> collect_missing_arguments env actual expected
73+
let print_expr_type_clash env trace ppf = begin
74+
(* this is the most frequent error. We should do whatever we can to provide
75+
specific guidance to this generic error before giving up *)
76+
let bottom_aliases_result = bottom_aliases trace in
77+
let missing_arguments = match bottom_aliases_result with
78+
| Some (actual, expected) -> collect_missing_arguments env actual expected
79+
| None -> assert false
80+
in
81+
let print_arguments =
82+
Format.pp_print_list
83+
~pp_sep:(fun ppf _ -> fprintf ppf ",@ ")
84+
(fun ppf (label, argtype) ->
85+
match label with
86+
| Asttypes.Nolabel -> fprintf ppf "@[%a@]" type_expr argtype
87+
| Labelled label ->
88+
fprintf ppf "@[(~%s: %a)@]" label type_expr argtype
89+
| Optional label ->
90+
fprintf ppf "@[(?%s: %a)@]" label type_expr argtype
91+
)
92+
in
93+
match missing_arguments with
94+
| Some [singleArgument] ->
95+
(* btw, you can't say "final arguments". Intermediate labeled
96+
arguments might be the ones missing *)
97+
fprintf ppf "@[@{<info>This call is missing an argument@} of type@ %a@]"
98+
print_arguments [singleArgument]
99+
| Some arguments ->
100+
fprintf ppf "@[<hv>@{<info>This call is missing arguments@} of type:@ %a@]"
101+
print_arguments arguments
102+
| None ->
103+
let missing_parameters = match bottom_aliases_result with
104+
| Some (actual, expected) -> collect_missing_arguments env expected actual
93105
| None -> assert false
94106
in
95-
let print_arguments =
96-
Format.pp_print_list
97-
~pp_sep:(fun ppf _ -> fprintf ppf ",@ ")
98-
(fun ppf (label, argtype) ->
99-
match label with
100-
| Asttypes.Nolabel -> fprintf ppf "@[%a@]" type_expr argtype
101-
| Labelled label ->
102-
fprintf ppf "@[(~%s: %a)@]" label type_expr argtype
103-
| Optional label ->
104-
fprintf ppf "@[(?%s: %a)@]" label type_expr argtype
105-
)
106-
in
107-
match missing_arguments with
108-
| Some [singleArgument] ->
109-
(* btw, you can't say "final arguments". Intermediate labeled
110-
arguments might be the ones missing *)
111-
fprintf ppf "@[@{<info>This call is missing an argument@} of type@ %a@]"
112-
print_arguments [singleArgument]
107+
begin match missing_parameters with
108+
| Some [singleParameter] ->
109+
fprintf ppf "@[This value might need to be @{<info>wrapped in a function@ that@ takes@ an@ extra@ parameter@}@ of@ type@ %a@]@,@,"
110+
print_arguments [singleParameter];
111+
fprintf ppf "@[@{<info>Here's the original error message@}@]@,"
113112
| Some arguments ->
114-
fprintf ppf "@[<hv>@{<info>This call is missing arguments@} of type:@ %a@]"
115-
print_arguments arguments
116-
| None ->
117-
let missing_parameters = match bottom_aliases_result with
118-
| Some (actual, expected) -> collect_missing_arguments env expected actual
119-
| None -> assert false
120-
in
121-
begin match missing_parameters with
122-
| Some [singleParameter] ->
123-
fprintf ppf "@[This value might need to be @{<info>wrapped in a function@ that@ takes@ an@ extra@ parameter@}@ of@ type@ %a@]@,@,"
124-
print_arguments [singleParameter];
125-
fprintf ppf "@[@{<info>Here's the original error message@}@]@,"
126-
| Some arguments ->
127-
fprintf ppf "@[This value seems to @{<info>need to be wrapped in a function that takes extra@ arguments@}@ of@ type:@ @[<hv>%a@]@]@,@,"
128-
print_arguments arguments;
129-
fprintf ppf "@[@{<info>Here's the original error message@}@]@,"
130-
| None -> ()
131-
end;
113+
fprintf ppf "@[This value seems to @{<info>need to be wrapped in a function that takes extra@ arguments@}@ of@ type:@ @[<hv>%a@]@]@,@,"
114+
print_arguments arguments;
115+
fprintf ppf "@[@{<info>Here's the original error message@}@]@,"
116+
| None -> ()
117+
end;
132118

133-
super_report_unification_error ppf env trace
134-
(function ppf ->
135-
fprintf ppf "This has type:")
136-
(function ppf ->
137-
fprintf ppf "Somewhere wanted:");
138-
show_extra_help ppf env trace;
139-
end
119+
super_report_unification_error ppf env trace
120+
(function ppf ->
121+
fprintf ppf "This has type:")
122+
(function ppf ->
123+
fprintf ppf "Somewhere wanted:");
124+
show_extra_help ppf env trace;
125+
end
140126

141127
(* Pasted from typecore.ml. Needed for some cases in report_error below *)
142128
(* Records *)

jscomp/super_errors/super_typemod.ml

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,12 @@ open Printtyp
22

33
let fprintf = Format.fprintf
44

5-
let non_generalizable_msg ppf ~result ~is_module print_fallback_msg =
6-
let contain_vs_be =
7-
if is_module then "This module seems to contain" else "This seems to be" in
8-
match result with
9-
| (_, true, _) :: _ ->
10-
fprintf ppf "@[<v>\
11-
@{<info>%s a ReasonReact reducerComponentWithRetainedProps?@}@ \
12-
The retained props feature is deprecated.@ \
13-
Please use a regular @{<info>reducerComponent@} and keep the props you want to retain in state.\
14-
@]"
15-
contain_vs_be
16-
| (true, _, _) :: _->
17-
fprintf ppf "@[<v>\
18-
@[\
19-
@{<info>%s a ReasonReact reducerComponent?@}@ \
20-
We don't have@ all@ the@ type@ info@ for@ its@ @{<info>state@}.@ \
21-
Make sure you've done the following: @]@,@,\
22-
@[- Define the component `make` function@]@,\
23-
@[- Define `reducer` in that `make` body@]@,\
24-
@[- Annotate reducer's second parameter (state) with the desired state type\
25-
@]\
26-
@]"
27-
contain_vs_be
28-
| (_, _, true) :: _->
29-
fprintf ppf "@[<v>\
30-
@[\
31-
@{<info>%s a ReasonReact reducerComponent?@}@ \
32-
We don't have@ all@ the@ type@ info@ for@ its@ @{<info>action@}.@ \
33-
Make sure you've done the following: @]@,@,\
34-
@[- Define the component `make` function@]@,\
35-
@[- Define `reducer` in that `make` body@]@,\
36-
@[- Annotate reducer's first parameter (action) with the desired action type\
37-
@]\
38-
@]"
39-
contain_vs_be
40-
| _ ->
41-
fprintf ppf
42-
"%a@,@,\
43-
@[This happens when the type system senses there's a mutation/side-effect,@ in combination with a polymorphic value.@,\
44-
@{<info>Using or annotating that value usually solves it.@}@ \
45-
More info:@ https://realworldocaml.org/v1/en/html/imperative-programming-1.html#side-effects-and-weak-polymorphism@]"
46-
print_fallback_msg ()
5+
let non_generalizable_msg ppf print_fallback_msg =
6+
fprintf ppf
7+
"%a@,@,\
8+
@[This happens when the type system senses there's a mutation/side-effect,@ in combination with a polymorphic value.@,\
9+
@{<info>Using or annotating that value usually solves it.@}@]"
10+
print_fallback_msg ()
4711

4812
(* taken from https://github.com/rescript-lang/ocaml/blob/d4144647d1bf9bc7dc3aadc24c25a7efa3a67915/typing/typemod.ml#L1754 *)
4913
(* modified branches are commented *)
@@ -53,8 +17,6 @@ let report_error ppf = function
5317
fprintf ppf "@[<v>";
5418
non_generalizable_msg
5519
ppf
56-
~result:([Super_reason_react.component_spec_weak_type_variables typ])
57-
~is_module:false
5820
(fun ppf () ->
5921
fprintf ppf
6022
"@[This expression's type contains type variables that can't be generalized:@,@{<error>%a@}@]"
@@ -65,8 +27,6 @@ let report_error ppf = function
6527
fprintf ppf "@[<v>";
6628
non_generalizable_msg
6729
ppf
68-
~result:(Super_reason_react.component_spec_weak_type_variables_in_module_type mty)
69-
~is_module:true
7030
(fun ppf () ->
7131
fprintf ppf
7232
"@[The type of this module contains type variables that cannot be generalized:@,@{<error>%a@}@]"

0 commit comments

Comments
 (0)