@@ -62,9 +62,10 @@ let is_record_type ~extract_concrete_typedecl ~env ty =
62
62
| _ -> false
63
63
with _ -> false
64
64
65
- let print_extra_type_clash_help ~extract_concrete_typedecl ~env ppf trace
65
+ let print_extra_type_clash_help ~extract_concrete_typedecl ~env ppf
66
+ (bottom_aliases : (Types.type_expr * Types.type_expr) option )
66
67
type_clash_context =
67
- match (type_clash_context, trace ) with
68
+ match (type_clash_context, bottom_aliases ) with
68
69
| Some (MathOperator {for_float; operator; is_constant} ), _ -> (
69
70
let operator_for_other_type =
70
71
match operator with
@@ -86,12 +87,8 @@ let print_extra_type_clash_help ~extract_concrete_typedecl ~env ppf trace
86
87
| _ -> " compute"
87
88
in
88
89
(* TODO check int vs float explicitly before showing this *)
89
- (match (operator, trace) with
90
- | ( " +" ,
91
- [
92
- ({Types. desc = Tconstr (p1, _, _)}, _);
93
- ({desc = Tconstr (p2, _, _)}, _);
94
- ] )
90
+ (match (operator, bottom_aliases) with
91
+ | " +" , Some ({Types. desc = Tconstr (p1, _, _)}, {desc = Tconstr (p2, _, _)})
95
92
when Path. same Predef. path_string p1 || Path. same Predef. path_string p2 ->
96
93
fprintf ppf
97
94
" \n\n \
@@ -111,7 +108,7 @@ let print_extra_type_clash_help ~extract_concrete_typedecl ~env ppf trace
111
108
@{<info>Belt.Float.toInt@} and @{<info>Belt.Int.fromFloat@}."
112
109
operator_text
113
110
(if for_float then " float" else " int" ));
114
- match (is_constant, trace ) with
111
+ match (is_constant, bottom_aliases ) with
115
112
| Some constant , _ ->
116
113
if for_float then
117
114
fprintf ppf
@@ -125,11 +122,8 @@ let print_extra_type_clash_help ~extract_concrete_typedecl ~env ppf trace
125
122
\ - Make @{<info>%s@} an @{<info>int@} by removing the dot or \
126
123
explicitly converting to int"
127
124
constant
128
- | ( _,
129
- [
130
- ({Types. desc = Tconstr (p1, _, _)}, _);
131
- ({desc = Tconstr (p2, _, _)}, _);
132
- ] ) -> (
125
+ | _, Some ({Types. desc = Tconstr (p1, _, _)}, {desc = Tconstr (p2, _, _)})
126
+ -> (
133
127
match (Path. name p1, Path. name p2) with
134
128
| "float" , "int" | "int" , "float" ->
135
129
fprintf ppf
@@ -171,18 +165,15 @@ let print_extra_type_clash_help ~extract_concrete_typedecl ~env ppf trace
171
165
\ - Use a tuple, if your array is of fixed length. Tuples can mix types \
172
166
freely, and compiles to a JavaScript array. Example of a tuple: `let \
173
167
myTuple = (10, \" hello\" , 15.5, true)"
174
- | ( _,
175
- [
176
- ({Types. desc = Tconstr (_p1, _, _)}, _); ({desc = Tconstr (p2, _, _)}, _);
177
- ] )
168
+ | _, Some ({Types. desc = Tconstr (_p1, _, _)}, {desc = Tconstr (p2, _, _)})
178
169
when Path. same Predef. path_unit p2 ->
179
170
fprintf ppf
180
171
" \n\n \
181
172
\ - Did you mean to assign this to a variable?\n \
182
173
\ - If you don't care about the result of this expression, you can \
183
174
assign it to @{<info>_@} via @{<info>let _ = ...@} or pipe it to \
184
175
@{<info>ignore@} via @{<info>expression->ignore@}\n\n "
185
- | _, [ ({desc = Tobject _}, _); (( {Types. desc = Tconstr _} as t1), _)]
176
+ | _, Some ({desc = Tobject _}, ( {Types. desc = Tconstr _} as t1))
186
177
when is_record_type ~extract_concrete_typedecl ~env t1 ->
187
178
fprintf ppf
188
179
" \n\n \
@@ -191,6 +182,9 @@ let print_extra_type_clash_help ~extract_concrete_typedecl ~env ppf trace
191
182
\ - Did you mean to pass a record instead of an object? Objects are \
192
183
written with quoted keys, and records with unquoted keys. Remove the \
193
184
quotes from the object keys to pass it as a record instead of object. \n\n "
185
+ | _, Some ({Types. desc = Tconstr (p1, _, _)}, _)
186
+ when Path. same p1 Predef. path_promise ->
187
+ fprintf ppf " \n\n - Did you mean to await this promise before using it?\n "
194
188
| _ -> ()
195
189
196
190
let type_clash_context_from_function sexp sfunct =
0 commit comments