@@ -62,9 +62,10 @@ let is_record_type ~extract_concrete_typedecl ~env ty =
6262 | _ -> false
6363 with _ -> false
6464
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 )
6667 type_clash_context =
67- match (type_clash_context, trace ) with
68+ match (type_clash_context, bottom_aliases ) with
6869 | Some (MathOperator {for_float; operator; is_constant} ), _ -> (
6970 let operator_for_other_type =
7071 match operator with
@@ -86,12 +87,8 @@ let print_extra_type_clash_help ~extract_concrete_typedecl ~env ppf trace
8687 | _ -> " compute"
8788 in
8889 (* 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, _, _)})
9592 when Path. same Predef. path_string p1 || Path. same Predef. path_string p2 ->
9693 fprintf ppf
9794 " \n\n \
@@ -111,7 +108,7 @@ let print_extra_type_clash_help ~extract_concrete_typedecl ~env ppf trace
111108 @{<info>Belt.Float.toInt@} and @{<info>Belt.Int.fromFloat@}."
112109 operator_text
113110 (if for_float then " float" else " int" ));
114- match (is_constant, trace ) with
111+ match (is_constant, bottom_aliases ) with
115112 | Some constant , _ ->
116113 if for_float then
117114 fprintf ppf
@@ -125,11 +122,8 @@ let print_extra_type_clash_help ~extract_concrete_typedecl ~env ppf trace
125122 \ - Make @{<info>%s@} an @{<info>int@} by removing the dot or \
126123 explicitly converting to int"
127124 constant
128- | ( _,
129- [
130- ({Types. desc = Tconstr (p1, _, _)}, _);
131- ({desc = Tconstr (p2, _, _)}, _);
132- ] ) -> (
125+ | _, Some ({Types. desc = Tconstr (p1, _, _)}, {desc = Tconstr (p2, _, _)})
126+ -> (
133127 match (Path. name p1, Path. name p2) with
134128 | "float" , "int" | "int" , "float" ->
135129 fprintf ppf
@@ -171,18 +165,15 @@ let print_extra_type_clash_help ~extract_concrete_typedecl ~env ppf trace
171165 \ - Use a tuple, if your array is of fixed length. Tuples can mix types \
172166 freely, and compiles to a JavaScript array. Example of a tuple: `let \
173167 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, _, _)})
178169 when Path. same Predef. path_unit p2 ->
179170 fprintf ppf
180171 " \n\n \
181172 \ - Did you mean to assign this to a variable?\n \
182173 \ - If you don't care about the result of this expression, you can \
183174 assign it to @{<info>_@} via @{<info>let _ = ...@} or pipe it to \
184175 @{<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))
186177 when is_record_type ~extract_concrete_typedecl ~env t1 ->
187178 fprintf ppf
188179 " \n\n \
@@ -191,6 +182,9 @@ let print_extra_type_clash_help ~extract_concrete_typedecl ~env ppf trace
191182 \ - Did you mean to pass a record instead of an object? Objects are \
192183 written with quoted keys, and records with unquoted keys. Remove the \
193184 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 "
194188 | _ -> ()
195189
196190let type_clash_context_from_function sexp sfunct =
0 commit comments