@@ -1709,13 +1709,13 @@ let rec type_approx env sexp =
1709
1709
raise(Error (sexp.pexp_loc, env, Expr_type_clash (trace, None )))
1710
1710
end ;
1711
1711
ty1
1712
- | Pexp_coerce (e , sty1 , sty2 ) ->
1712
+ | Pexp_coerce (e , () , sty2 ) ->
1713
1713
let approx_ty_opt = function
1714
1714
| None -> newvar ()
1715
1715
| Some sty -> approx_type env sty
1716
1716
in
1717
1717
let ty = type_approx env e
1718
- and ty1 = approx_ty_opt sty1
1718
+ and ty1 = approx_ty_opt None
1719
1719
and ty2 = approx_type env sty2 in
1720
1720
begin try unify env ty ty1 with Unify trace ->
1721
1721
raise(Error (sexp.pexp_loc, env, Expr_type_clash (trace, None )))
@@ -2571,87 +2571,62 @@ and type_expect_ ?type_clash_context ?in_function ?(recarg=Rejected) env sexp ty
2571
2571
exp_extra =
2572
2572
(Texp_constraint cty, loc, sexp.pexp_attributes) :: arg.exp_extra;
2573
2573
}
2574
- | Pexp_coerce (sarg , sty , sty' ) ->
2574
+ | Pexp_coerce (sarg , () , sty' ) ->
2575
2575
let separate = true in (* always separate, 1% slowdown for lablgtk *)
2576
2576
(* Also see PR#7199 for a problem with the following:
2577
2577
let separate = Env.has_local_constraints env in*)
2578
- let (arg, ty',cty,cty') =
2579
- match sty with
2580
- | None ->
2581
- let (cty', force) =
2582
- Typetexp. transl_simple_type_delayed env sty'
2583
- in
2584
- let ty' = cty'.ctyp_type in
2585
- if separate then begin_def () ;
2586
- let arg = type_exp env sarg in
2587
- let gen =
2588
- if separate then begin
2589
- end_def () ;
2590
- let tv = newvar () in
2591
- let gen = generalizable tv.level arg.exp_type in
2592
- (try unify_var env tv arg.exp_type with Unify trace ->
2593
- raise(Error (arg.exp_loc, env, Expr_type_clash (trace, type_clash_context))));
2594
- gen
2595
- end else true
2596
- in
2597
- begin match arg.exp_desc, ! self_coercion, (repr ty').desc with
2598
- | _ when free_variables ~env arg.exp_type = []
2599
- && free_variables ~env ty' = [] ->
2600
- if not gen && (* first try a single coercion *)
2601
- let snap = snapshot () in
2602
- let ty, _b = enlarge_type env ty' in
2603
- try
2604
- force () ; Ctype. unify env arg.exp_type ty; true
2605
- with Unify _ ->
2606
- backtrack snap; false
2607
- then ()
2608
- else begin try
2609
- let force' = subtype env arg.exp_type ty' in
2610
- force () ; force' () ;
2611
- with Subtype (tr1 , tr2 ) ->
2612
- (* prerr_endline "coercion failed"; *)
2613
- raise(Error (loc, env, Not_subtype (tr1, tr2)))
2614
- end ;
2615
- | _ ->
2616
- let ty, b = enlarge_type env ty' in
2617
- force () ;
2618
- begin try Ctype. unify env arg.exp_type ty with Unify trace ->
2619
- raise(Error (sarg.pexp_loc, env,
2620
- Coercion_failure (ty', full_expand env ty', trace, b)))
2621
- end
2622
- end ;
2623
- (arg, ty', None , cty')
2624
- | Some sty ->
2625
- if separate then begin_def () ;
2626
- let (cty, force) =
2627
- Typetexp. transl_simple_type_delayed env sty
2628
- and (cty', force') =
2629
- Typetexp. transl_simple_type_delayed env sty'
2630
- in
2631
- let ty = cty.ctyp_type in
2632
- let ty' = cty'.ctyp_type in
2633
- begin try
2634
- let force'' = subtype env ty ty' in
2635
- force () ; force' () ; force'' ()
2636
- with Subtype (tr1 , tr2 ) ->
2637
- raise(Error (loc, env, Not_subtype (tr1, tr2)))
2638
- end ;
2578
+ let (arg, ty',cty') =
2579
+ let (cty', force) =
2580
+ Typetexp. transl_simple_type_delayed env sty'
2581
+ in
2582
+ let ty' = cty'.ctyp_type in
2583
+ if separate then begin_def () ;
2584
+ let arg = type_exp env sarg in
2585
+ let gen =
2639
2586
if separate then begin
2640
2587
end_def () ;
2641
- generalize_structure ty;
2642
- generalize_structure ty';
2643
- (type_argument env sarg ty (instance env ty),
2644
- instance env ty', Some cty, cty')
2645
- end else
2646
- (type_argument env sarg ty ty, ty', Some cty, cty')
2588
+ let tv = newvar () in
2589
+ let gen = generalizable tv.level arg.exp_type in
2590
+ (try unify_var env tv arg.exp_type with Unify trace ->
2591
+ raise(Error (arg.exp_loc, env, Expr_type_clash (trace, type_clash_context))));
2592
+ gen
2593
+ end else true
2594
+ in
2595
+ begin match arg.exp_desc, ! self_coercion, (repr ty').desc with
2596
+ | _ when free_variables ~env arg.exp_type = []
2597
+ && free_variables ~env ty' = [] ->
2598
+ if not gen && (* first try a single coercion *)
2599
+ let snap = snapshot () in
2600
+ let ty, _b = enlarge_type env ty' in
2601
+ try
2602
+ force () ; Ctype. unify env arg.exp_type ty; true
2603
+ with Unify _ ->
2604
+ backtrack snap; false
2605
+ then ()
2606
+ else begin try
2607
+ let force' = subtype env arg.exp_type ty' in
2608
+ force () ; force' () ;
2609
+ with Subtype (tr1 , tr2 ) ->
2610
+ (* prerr_endline "coercion failed"; *)
2611
+ raise(Error (loc, env, Not_subtype (tr1, tr2)))
2612
+ end ;
2613
+ | _ ->
2614
+ let ty, b = enlarge_type env ty' in
2615
+ force () ;
2616
+ begin try Ctype. unify env arg.exp_type ty with Unify trace ->
2617
+ raise(Error (sarg.pexp_loc, env,
2618
+ Coercion_failure (ty', full_expand env ty', trace, b)))
2619
+ end
2620
+ end ;
2621
+ (arg, ty', cty')
2647
2622
in
2648
2623
rue {
2649
2624
exp_desc = arg.exp_desc;
2650
2625
exp_loc = arg.exp_loc;
2651
2626
exp_type = ty';
2652
2627
exp_attributes = arg.exp_attributes;
2653
2628
exp_env = env;
2654
- exp_extra = (Texp_coerce (cty , cty'), loc, sexp.pexp_attributes) ::
2629
+ exp_extra = (Texp_coerce (() , cty'), loc, sexp.pexp_attributes) ::
2655
2630
arg.exp_extra;
2656
2631
}
2657
2632
| Pexp_send (e , {txt =met } ) ->
0 commit comments