@@ -217,7 +217,7 @@ type error =
217
217
Env .closure_context option *
218
218
Env .shared_context option
219
219
| Local_application_complete of Asttypes .arg_label * [`Prefix |`Single_arg |`Entire_apply ]
220
- | Param_mode_mismatch of type_expr * Alloc .equate_error
220
+ | Param_mode_mismatch of Alloc .equate_error
221
221
| Uncurried_function_escapes of Alloc .error
222
222
| Local_return_annotation_mismatch of Location .t
223
223
| Function_returns_local
@@ -847,9 +847,9 @@ let mode_annots_from_pat_attrs pat =
847
847
in
848
848
Typemode. transl_mode_annots modes, {pat with ppat_attributes}
849
849
850
- let apply_mode_annots ~loc ~env ~ ty_expected (m : Alloc.Const.Option.t ) mode =
850
+ let apply_mode_annots ~loc ~env (m : Alloc.Const.Option.t ) mode =
851
851
let error axis =
852
- raise (Error (loc, env, Param_mode_mismatch (ty_expected, axis) ))
852
+ raise (Error (loc, env, Param_mode_mismatch axis))
853
853
in
854
854
Option. iter (fun locality ->
855
855
match Locality. equate (Locality. of_const locality) (Alloc. locality mode) with
@@ -4108,7 +4108,7 @@ let type_approx_fun_one_param
4108
4108
in
4109
4109
Option. iter
4110
4110
(fun mode_annots ->
4111
- apply_mode_annots ~loc ~env ~ty_expected mode_annots arg_mode)
4111
+ apply_mode_annots ~loc ~env mode_annots arg_mode)
4112
4112
mode_annots;
4113
4113
if has_poly then begin
4114
4114
match spato with
@@ -4781,7 +4781,7 @@ let split_function_ty
4781
4781
generalize_structure ty_arg;
4782
4782
generalize_structure ty_ret)
4783
4783
in
4784
- apply_mode_annots ~loc: loc_fun ~env ~ty_expected mode_annots arg_mode;
4784
+ apply_mode_annots ~loc: loc_fun ~env mode_annots arg_mode;
4785
4785
if not has_poly && not (tpoly_is_mono ty_arg) && ! Clflags. principal
4786
4786
&& get_level ty_arg < Btype. generic_level then begin
4787
4787
let snap = Btype. snapshot () in
@@ -9975,11 +9975,13 @@ let report_error ~loc env = function
9975
9975
| `Regionality _ ->
9976
9976
escaping_hint fail_reason submode_reason closure_context
9977
9977
in
9978
- Location. errorf ~loc ~sub begin
9978
+ Location. errorf ~loc ~sub " %t " begin
9979
9979
match fail_reason with
9980
- | `Regionality _ -> " This value escapes its region"
9981
- | `Uniqueness _ -> " Found a shared value where a unique value was expected"
9982
- | `Linearity _ -> " Found a once value where a many value was expected"
9980
+ | `Regionality _ -> Format. dprintf " This value escapes its region"
9981
+ | `Uniqueness {left; right} -> Format. dprintf " Found a %a value where a %a value was expected"
9982
+ Uniqueness.Const. print left Uniqueness.Const. print right
9983
+ | `Linearity {left; right} -> Format. dprintf " Found a %a value where a %a value was expected"
9984
+ Linearity.Const. print left Linearity.Const. print right
9983
9985
end
9984
9986
| Local_application_complete (lbl , loc_kind ) ->
9985
9987
let sub =
@@ -10004,25 +10006,32 @@ let report_error ~loc env = function
10004
10006
Location. errorf ~loc ~sub
10005
10007
" @[This application is complete, but surplus arguments were provided afterwards.@ \
10006
10008
When passing or calling a local value, extra arguments are passed in a separate application.@]"
10007
- | Param_mode_mismatch (ty , (_ , mkind )) ->
10008
- let mkind =
10009
- match mkind with
10010
- | `Locality _ -> " local"
10011
- | `Uniqueness _ -> " unique"
10012
- | `Linearity _ -> " once"
10013
- in
10014
- Location. errorf ~loc
10015
- " @[This function has a %s parameter, but was expected to have type:@ %a@]"
10016
- mkind Printtyp. type_expr ty
10009
+ | Param_mode_mismatch (s , mkind ) ->
10010
+ let print_error f (step , {Solver. left; Solver. right} ) =
10011
+ let actual, expected =
10012
+ match (step : equate_step ) with
10013
+ | Left_le_right -> left, right
10014
+ | Right_le_left -> right, left
10015
+ in
10016
+ Location. errorf ~loc
10017
+ " @[This function takes a %a parameter,@ \
10018
+ but was expected to take a %a parameter.@]"
10019
+ f actual f expected
10020
+ in begin
10021
+ match mkind with
10022
+ | `Locality e -> print_error Locality.Const. print (s, e)
10023
+ | `Uniqueness e -> print_error Uniqueness.Const. print (s, e)
10024
+ | `Linearity e -> print_error Linearity.Const. print (s, e)
10025
+ end
10017
10026
| Uncurried_function_escapes e -> begin
10018
10027
match e with
10019
10028
| `Locality _ ->
10020
10029
Location. errorf ~loc " This function or one of its parameters escape their region @ \
10021
10030
when it is partially applied."
10022
10031
| `Uniqueness _ -> assert false
10023
- | `Linearity _ ->
10024
- Location. errorf ~loc " This function when partially applied returns a once value,@ \
10025
- but expected to be many. "
10032
+ | `Linearity {left; right} ->
10033
+ Location. errorf ~loc " This function when partially applied returns a %a value,@ \
10034
+ but expected to be %a. " Linearity.Const. print left Linearity.Const. print right
10026
10035
end
10027
10036
| Local_return_annotation_mismatch _ ->
10028
10037
Location. errorf ~loc
0 commit comments