@@ -6304,11 +6304,13 @@ and type_let
6304
6304
end_def () ;
6305
6305
iter_pattern_variables_type generalize_structure pvs;
6306
6306
List. map (fun (m , pat ) ->
6307
- generalize_structure pat.pat_type;
6308
- m, {pat with pat_type = instance pat.pat_type}
6307
+ let ty = pat.pat_type in
6308
+ generalize_structure ty;
6309
+ m, {pat with pat_type = instance ty}, ty
6309
6310
) pat_list
6310
- end else
6311
- pat_list
6311
+ end else begin
6312
+ List. map (fun (m , pat ) -> (m, pat, pat.pat_type)) pat_list
6313
+ end
6312
6314
in
6313
6315
(* Only bind pattern variables after generalizing *)
6314
6316
List. iter (fun f -> f() ) force;
@@ -6342,7 +6344,7 @@ and type_let
6342
6344
|| (is_recursive && (Warnings. is_active Warnings. Unused_rec_flag ))))
6343
6345
attrs_list
6344
6346
in
6345
- let mode_pat_slot_list =
6347
+ let mode_typ_slot_list =
6346
6348
(* Algorithm to detect unused declarations in recursive bindings:
6347
6349
- During type checking of the definitions, we capture the 'value_used'
6348
6350
events on the bound identifiers and record them in a slot corresponding
@@ -6360,9 +6362,9 @@ and type_let
6360
6362
warning is 26, not 27.
6361
6363
*)
6362
6364
List. map2
6363
- (fun attrs (mode , pat ) ->
6365
+ (fun attrs (mode , pat , expected_ty ) ->
6364
6366
Builtin_attributes. warning_scope ~ppwarning: false attrs (fun () ->
6365
- if not warn_about_unused_bindings then mode, pat , None
6367
+ if not warn_about_unused_bindings then mode, expected_ty , None
6366
6368
else
6367
6369
let some_used = ref false in
6368
6370
(* has one of the identifier of this pattern been used? *)
@@ -6394,16 +6396,16 @@ and type_let
6394
6396
)
6395
6397
)
6396
6398
(Typedtree. pat_bound_idents pat);
6397
- mode, pat , Some slot
6399
+ mode, expected_ty , Some slot
6398
6400
))
6399
6401
attrs_list
6400
6402
pat_list
6401
6403
in
6402
6404
let exp_list =
6403
6405
List. map2
6404
- (fun {pvb_expr =sexp ; pvb_attributes; _} (mode , pat , slot ) ->
6406
+ (fun {pvb_expr =sexp ; pvb_attributes; _} (mode , expected_ty , slot ) ->
6405
6407
if is_recursive then current_slot := slot;
6406
- match get_desc pat.pat_type with
6408
+ match get_desc expected_ty with
6407
6409
| Tpoly (ty , tl ) ->
6408
6410
if ! Clflags. principal then begin_def () ;
6409
6411
let vars, ty' = instance_poly ~keep_names: true true tl ty in
@@ -6427,13 +6429,13 @@ and type_let
6427
6429
Builtin_attributes. warning_scope pvb_attributes (fun () ->
6428
6430
if rec_flag = Recursive then
6429
6431
type_unpacks exp_env mode
6430
- unpacks sexp (mk_expected pat.pat_type )
6432
+ unpacks sexp (mk_expected expected_ty )
6431
6433
else
6432
6434
type_expect exp_env mode
6433
- sexp (mk_expected pat.pat_type ))
6435
+ sexp (mk_expected expected_ty ))
6434
6436
in
6435
6437
exp, None )
6436
- spat_sexp_list mode_pat_slot_list in
6438
+ spat_sexp_list mode_typ_slot_list in
6437
6439
current_slot := None ;
6438
6440
if is_recursive && not ! rec_needed then begin
6439
6441
let {pvb_pat; pvb_attributes} = List. hd spat_sexp_list in
@@ -6444,7 +6446,7 @@ and type_let
6444
6446
)
6445
6447
end ;
6446
6448
List. iter2
6447
- (fun (_ ,pat ) (attrs , exp ) ->
6449
+ (fun (_ ,pat , _ ) (attrs , exp ) ->
6448
6450
Builtin_attributes. warning_scope ~ppwarning: false attrs
6449
6451
(fun () ->
6450
6452
ignore(check_partial env pat.pat_type pat.pat_loc
@@ -6456,13 +6458,13 @@ and type_let
6456
6458
let pvs = List. map (fun pv -> { pv with pv_type = instance pv.pv_type}) pvs in
6457
6459
end_def() ;
6458
6460
List. iter2
6459
- (fun (_ ,pat ) (exp , _ ) ->
6461
+ (fun (_ ,pat , _ ) (exp , _ ) ->
6460
6462
if maybe_expansive exp then
6461
6463
lower_contravariant env pat.pat_type)
6462
6464
pat_list exp_list;
6463
6465
iter_pattern_variables_type generalize pvs;
6464
6466
List. iter2
6465
- (fun (_ ,pat ) (exp , vars ) ->
6467
+ (fun (_ ,_ , expected_ty ) (exp , vars ) ->
6466
6468
match vars with
6467
6469
| None ->
6468
6470
(* We generalize expressions even if they are not bound to a variable
@@ -6478,12 +6480,12 @@ and type_let
6478
6480
| Some vars ->
6479
6481
if maybe_expansive exp then
6480
6482
lower_contravariant env exp.exp_type;
6481
- generalize_and_check_univars env " definition" exp pat.pat_type vars)
6483
+ generalize_and_check_univars env " definition" exp expected_ty vars)
6482
6484
pat_list exp_list;
6483
6485
let l = List. combine pat_list exp_list in
6484
6486
let l =
6485
6487
List. map2
6486
- (fun ((_ ,p ), (e , _ )) pvb ->
6488
+ (fun ((_ ,p , _ ), (e , _ )) pvb ->
6487
6489
{vb_pat= p; vb_expr= e; vb_attributes= pvb.pvb_attributes;
6488
6490
vb_loc= pvb.pvb_loc;
6489
6491
})
0 commit comments