Skip to content

Commit 54d6467

Browse files
authored
Fix incorrect sort in type_argument (#3972)
Correct sort in coercion case of [type_argument]
1 parent 957e5ce commit 54d6467

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

testsuite/tests/typing-layouts/omitted_arguments.ml

+14
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,17 @@ let evaluate =
7272
let _ =
7373
Printf.printf "\"real\" code (3.14): %.2f\n"
7474
(box_float (evaluate [|2; 3; 4|] ~size:1))
75+
76+
(* Omitting optional arg, where let binding is needed for function. *)
77+
module M = struct
78+
(* Putting this in a module defeats an optimization in simplif that removes an
79+
intermediate let binding where the bug occurs (it reduces [let x = y in
80+
...], but only if [y] is precisely a variable, which a projection from a
81+
module is not). *)
82+
let to_string ?(explicit_plus = false) x =
83+
if explicit_plus then "blah" else string_of_float (box_float x)
84+
end
85+
86+
let pi_to_string ~value_to_string = value_to_string #3.14
87+
let pi = pi_to_string ~value_to_string:M.to_string
88+
let () = Printf.printf "Omitting optional arg (3.14): %s\n" pi

testsuite/tests/typing-layouts/omitted_arguments.reference

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ Omitting named arg (6.29): 6.29
22
Omitting named arg (6.27): 6.27
33
Omitting named arg (9.42): 9.42
44
"real" code (3.14): 3.14
5+
Omitting optional arg (3.14): 3.14

typing/typecore.ml

+7-1
Original file line numberDiff line numberDiff line change
@@ -8146,10 +8146,16 @@ and type_argument ?explanation ?recarg ~overwrite env (mode : expected_mode) sar
81468146
(Warnings.Non_principal_labels "eliminated omittable argument");
81478147
(* let-expand to have side effects *)
81488148
let let_pat, let_var = var_pair ~mode:exp_mode "arg" texp.exp_type in
8149+
let let_pat_sort =
8150+
(* The sort of the let-bound variable, which here is always a function
8151+
(observe it is passed to [func], which builds an application of
8152+
it). *)
8153+
Jkind.Sort.value
8154+
in
81498155
re { texp with exp_type = ty_fun;
81508156
exp_desc =
81518157
Texp_let (Nonrecursive,
8152-
[{vb_pat=let_pat; vb_expr=texp; vb_sort=arg_sort;
8158+
[{vb_pat=let_pat; vb_expr=texp; vb_sort=let_pat_sort;
81538159
vb_attributes=[]; vb_loc=Location.none;
81548160
vb_rec_kind = Dynamic;
81558161
}],

0 commit comments

Comments
 (0)