File tree 3 files changed +32
-1
lines changed
testsuite/tests/typing-local
3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -449,4 +449,13 @@ let foo () =
449
449
()
450
450
[%% expect{|
451
451
val foo : unit -> unit = < fun>
452
- |}]
452
+ |}]
453
+
454
+ (* Values crosses modes when pattern-matching, an implication is that, closing
455
+ over [local int] won't force the closure to be [local]. *)
456
+ let foo (local_ x : int ) =
457
+ let bar y = x + y in
458
+ ref bar
459
+ [%% expect{|
460
+ val foo : local_ int -> (int -> int ) ref = < fun>
461
+ |}]
Original file line number Diff line number Diff line change @@ -2783,6 +2783,13 @@ let f () = ((fun x -> (fun y -> "") [@extension.curry])
2783
2783
val f : unit -> local_ string -> (string -> string ) = < fun>
2784
2784
|}];;
2785
2785
2786
+ (* mode crossing - the inner closure is [global] despite closing over [local_
2787
+ int] *)
2788
+ let f () = ((fun x y -> x + y) : (local_ int -> (int -> int )));;
2789
+ [%% expect{|
2790
+ val f : unit -> local_ int -> (int -> int ) = < fun>
2791
+ |}];;
2792
+
2786
2793
(* Illegal: the expected mode is global *)
2787
2794
let f () = local_ ((fun x y -> x + y) : (_ -> _));;
2788
2795
[%% expect{|
Original file line number Diff line number Diff line change @@ -804,6 +804,18 @@ let mode_cross_to_min env ty mode =
804
804
else
805
805
Value. disallow_right mode
806
806
807
+ (* cross the monadic fragment to max, and the comonadic fragment to min *)
808
+ let alloc_mode_cross_to_max_min env ty {monadic; comonadic} =
809
+ let (monadic, comonadic)=
810
+ if mode_cross env ty then
811
+ Alloc.Monadic. max, Alloc.Comonadic. min
812
+ else
813
+ monadic, comonadic
814
+ in
815
+ let monadic = Alloc.Monadic. disallow_left monadic in
816
+ let comonadic = Alloc.Comonadic. disallow_right comonadic in
817
+ {monadic; comonadic}
818
+
807
819
let expect_mode_cross env ty (expected_mode : expected_mode ) =
808
820
if mode_cross env ty then
809
821
{ expected_mode with
@@ -6676,6 +6688,9 @@ and type_function
6676
6688
Final_arg
6677
6689
| Some fun_alloc_mode ->
6678
6690
assert (not is_final_val_param);
6691
+ (* If the argument cross modes, it crosses to max on monadic
6692
+ axes, and min on comonadic axes. *)
6693
+ let arg_mode = alloc_mode_cross_to_max_min env ty_arg arg_mode in
6679
6694
begin match
6680
6695
Alloc. submode (Alloc. close_over arg_mode) fun_alloc_mode
6681
6696
with
You can’t perform that action at this time.
0 commit comments