@@ -191,11 +191,24 @@ type error =
191
191
| Layout_not_enabled of Layout .const
192
192
| Unboxed_int_literals_not_supported
193
193
| Unboxed_float_literals_not_supported
194
- | Function_arg_not_rep of type_expr * Layout.Violation .t
194
+ | Function_type_not_rep of type_expr * Layout.Violation .t
195
195
196
196
exception Error of Location. t * Env. t * error
197
197
exception Error_forward of Location. error
198
198
199
+ let error_of_filter_arrow_failure ~explanation in_function ty_fun
200
+ : filter_arrow_failure -> _ = function
201
+ | Unification_error unif_err ->
202
+ Expr_type_clash (unif_err, explanation, None )
203
+ | Label_mismatch { got; expected; expected_type} ->
204
+ Abstract_wrong_label { got; expected; expected_type; explanation }
205
+ | Not_a_function -> begin
206
+ match in_function with
207
+ | Some _ -> Too_many_arguments (ty_fun, explanation)
208
+ | None -> Not_a_function (ty_fun, explanation)
209
+ end
210
+ | Layout_error (ty , err ) -> Function_type_not_rep (ty, err)
211
+
199
212
(* Forward declaration, to be filled in by Typemod.type_module *)
200
213
201
214
let type_module =
@@ -3119,7 +3132,7 @@ let collect_unknown_apply_args env funct ty_fun mode_fun rev_args sargs ret_tvar
3119
3132
match type_sort ~why: Function_argument env ty_arg with
3120
3133
| Ok sort -> sort
3121
3134
| Error err -> raise(Error (funct.exp_loc, env,
3122
- Function_arg_not_rep (ty_arg,err)))
3135
+ Function_type_not_rep (ty_arg,err)))
3123
3136
in
3124
3137
(sort_arg, mode_arg, tpoly_get_mono ty_arg, mode_ret, ty_res)
3125
3138
| td ->
@@ -3164,7 +3177,7 @@ let collect_apply_args env funct ignore_labels ty_fun ty_fun0 mode_fun sargs ret
3164
3177
let sort_arg = match type_sort ~why: Function_argument env ty_arg with
3165
3178
| Ok sort -> sort
3166
3179
| Error err -> raise(Error (sarg1.pexp_loc, env,
3167
- Function_arg_not_rep (ty_arg, err)))
3180
+ Function_type_not_rep (ty_arg, err)))
3168
3181
in
3169
3182
let name = label_name l
3170
3183
and optional = is_optional l in
@@ -3623,17 +3636,8 @@ let rec type_function_approx env loc label spato sexp in_function ty_expected =
3623
3636
let { ty_arg; arg_mode; ty_ret; _ } =
3624
3637
try filter_arrow env ty_expected label ~force_tpoly: (not has_poly)
3625
3638
with Filter_arrow_failed err ->
3626
- let explanation = None in
3627
- let err = match err with
3628
- | Unification_error unif_err ->
3629
- Expr_type_clash (unif_err, explanation, None )
3630
- | Label_mismatch { got; expected; expected_type} ->
3631
- Abstract_wrong_label { got; expected; expected_type; explanation }
3632
- | Not_a_function -> begin
3633
- match in_function with
3634
- | Some _ -> Too_many_arguments (ty_fun, explanation)
3635
- | None -> Not_a_function (ty_fun, explanation)
3636
- end
3639
+ let err =
3640
+ error_of_filter_arrow_failure ~explanation: None in_function ty_fun err
3637
3641
in
3638
3642
raise (Error (loc_fun, env, err))
3639
3643
in
@@ -5762,16 +5766,8 @@ and type_function ?in_function loc attrs env (expected_mode : expected_mode)
5762
5766
in
5763
5767
try filter_arrow env ty_expected' arg_label ~force_tpoly
5764
5768
with Filter_arrow_failed err ->
5765
- let err = match err with
5766
- | Unification_error unif_err ->
5767
- Expr_type_clash (unif_err, explanation, None )
5768
- | Label_mismatch { got; expected; expected_type} ->
5769
- Abstract_wrong_label { got; expected; expected_type; explanation }
5770
- | Not_a_function -> begin
5771
- match in_function with
5772
- | Some _ -> Too_many_arguments (ty_fun, explanation)
5773
- | None -> Not_a_function (ty_fun, explanation)
5774
- end
5769
+ let err =
5770
+ error_of_filter_arrow_failure ~explanation in_function ty_fun err
5775
5771
in
5776
5772
raise (Error (loc_fun, env, err))
5777
5773
in
@@ -6372,10 +6368,17 @@ and type_argument ?explanation ?recarg env (mode : expected_mode) sarg
6372
6368
let eta_mode = Value_mode. local_to_regional (Value_mode. of_alloc marg) in
6373
6369
let eta_pat, eta_var = var_pair ~mode: eta_mode " eta" ty_arg in
6374
6370
(* CR layouts v10: When we add abstract layouts, the eta expansion here
6375
- becomes impossible in some cases - we'll need good errors and test
6376
- cases instead of `type_sort_exn`. *)
6377
- let arg_sort = type_sort_exn env ~why: Function_argument ty_arg in
6378
- let ret_sort = type_sort_exn env ~why: Function_argument ty_res in
6371
+ becomes impossible in some cases - we'll need better errors. For test
6372
+ cases, look toward the end of
6373
+ typing-layouts-missing-cmi/function_arg.ml *)
6374
+ let type_sort ~why ty =
6375
+ match type_sort ~why env ty with
6376
+ | Ok sort -> sort
6377
+ | Error err ->
6378
+ raise(Error (sarg.pexp_loc, env, Function_type_not_rep (ty, err)))
6379
+ in
6380
+ let arg_sort = type_sort ~why: Function_argument ty_arg in
6381
+ let ret_sort = type_sort ~why: Function_result ty_res in
6379
6382
let func texp =
6380
6383
let ret_mode = Value_mode. of_alloc mret in
6381
6384
let e =
@@ -8365,12 +8368,11 @@ let report_error ~loc env = function
8365
8368
| Unboxed_float_literals_not_supported ->
8366
8369
Location. errorf ~loc
8367
8370
" @[Unboxed float literals aren't supported yet.@]"
8368
- | Function_arg_not_rep ( ty_arg ,violation ) ->
8371
+ | Function_type_not_rep ( ty ,violation ) ->
8369
8372
Location. errorf ~loc
8370
- " @[Function argument of type %a@ is not representable.@]@ %a"
8371
- Printtyp. type_expr ty_arg
8373
+ " @[Function arguments and returns must be representable.@]@ %a"
8372
8374
(Layout.Violation. report_with_offender
8373
- ~offender: (fun ppf -> Printtyp. type_expr ppf ty_arg )) violation
8375
+ ~offender: (fun ppf -> Printtyp. type_expr ppf ty )) violation
8374
8376
8375
8377
let report_error ~loc env err =
8376
8378
Printtyp. wrap_printing_env ~error: true env
0 commit comments