@@ -76,7 +76,8 @@ type type_clash_context =
7676 | MaybeUnwrapOption
7777 | IfCondition
7878 | IfReturn
79- | Switch
79+ | SwitchReturn
80+ | TryReturn
8081 | StringConcat
8182 | ComparisonOperator
8283 | MathOperator of {
@@ -107,7 +108,8 @@ let error_expected_type_text ppf type_clash_context =
107108 fprintf ppf " But this function argument is expecting:"
108109 | Some ComparisonOperator ->
109110 fprintf ppf " But it's being compared to something of type:"
110- | Some Switch -> fprintf ppf " But this switch is expected to return:"
111+ | Some SwitchReturn -> fprintf ppf " But this switch is expected to return:"
112+ | Some TryReturn -> fprintf ppf " But this try/catch is expected to return:"
111113 | Some IfCondition ->
112114 fprintf ppf " But @{<info>if@} conditions must always be of type:"
113115 | Some IfReturn ->
@@ -121,7 +123,8 @@ let error_expected_type_text ppf type_clash_context =
121123 " But it's being used with the @{<info>%s@} operator, which works on:"
122124 operator
123125 | Some StringConcat -> fprintf ppf " But string concatenation is expecting:"
124- | _ -> fprintf ppf " But it's expected to have type:"
126+ | Some MaybeUnwrapOption | None ->
127+ fprintf ppf " But it's expected to have type:"
125128
126129let is_record_type ~extract_concrete_typedecl ~env ty =
127130 try
@@ -201,11 +204,17 @@ let print_extra_type_clash_help ~extract_concrete_typedecl ~env loc ppf
201204 (if for_float then " int" else " float" )
202205 | _ -> () )
203206 | _ -> () )
204- | Some Switch , _ ->
207+ | Some SwitchReturn , _ ->
205208 fprintf ppf
206209 " \n\n \
207- \ All branches in a @{<info>switch@} must return the same type. To fix \
208- this, change your branch to return the expected type."
210+ \ All branches in a @{<info>switch@} must return the same type.@,\
211+ To fix this, change your branch to return the expected type."
212+ | Some TryReturn , _ ->
213+ fprintf ppf
214+ " \n\n \
215+ \ The @{<info>try@} body and the @{<info>catch@} block must return the \
216+ same type.@,\
217+ To fix this, change your try/catch blocks to return the expected type."
209218 | Some IfCondition , _ ->
210219 fprintf ppf
211220 " \n\n \
0 commit comments