|
| 1 | +(* |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + *) |
| 7 | + |
| 8 | +open OUnit2 |
| 9 | +open Type |
| 10 | + |
| 11 | +let assert_forced_to_any s = |
| 12 | + match Constraint.ForcingState.force ~on_error:AnyT.error s with |
| 13 | + | AnyT _ -> () |
| 14 | + | _ -> failwith "Invalid type" |
| 15 | + |
| 16 | +let forcing_state_tests = |
| 17 | + [ |
| 18 | + ( "invalid_self_recursive" >:: fun _ -> |
| 19 | + let rec s_lazy = |
| 20 | + lazy |
| 21 | + (Constraint.ForcingState.of_lazy_t |
| 22 | + ~error_reason:Reason.(locationless_reason RNull) |
| 23 | + (lazy (Constraint.ForcingState.force ~on_error:AnyT.error (Lazy.force s_lazy))) |
| 24 | + ) |
| 25 | + in |
| 26 | + let s = Lazy.force s_lazy in |
| 27 | + assert_forced_to_any s |
| 28 | + ); |
| 29 | + ( "invalid_mutually_recursive" >:: fun _ -> |
| 30 | + let rec s1_lazy = |
| 31 | + lazy |
| 32 | + (Constraint.ForcingState.of_lazy_t |
| 33 | + ~error_reason:Reason.(locationless_reason RNull) |
| 34 | + (lazy (Constraint.ForcingState.force ~on_error:AnyT.error (Lazy.force s2_lazy))) |
| 35 | + ) |
| 36 | + and s2_lazy = |
| 37 | + lazy |
| 38 | + (Constraint.ForcingState.of_lazy_t |
| 39 | + ~error_reason:Reason.(locationless_reason RNull) |
| 40 | + (lazy (Constraint.ForcingState.force ~on_error:AnyT.error (Lazy.force s1_lazy))) |
| 41 | + ) |
| 42 | + in |
| 43 | + let s1 = Lazy.force s1_lazy in |
| 44 | + let s2 = Lazy.force s2_lazy in |
| 45 | + assert_forced_to_any s1; |
| 46 | + assert_forced_to_any s2 |
| 47 | + ); |
| 48 | + ( "invalid_self_recursive_mapped" >:: fun _ -> |
| 49 | + let rec s_lazy = |
| 50 | + lazy |
| 51 | + (Constraint.ForcingState.of_lazy_t |
| 52 | + ~error_reason:Reason.(locationless_reason RNull) |
| 53 | + (lazy (Constraint.ForcingState.force ~on_error:AnyT.error (Lazy.force s_lazy))) |
| 54 | + ) |
| 55 | + in |
| 56 | + let s = Lazy.force s_lazy in |
| 57 | + let s' = Constraint.ForcingState.map ~on_error:AnyT.error ~f:Base.Fn.id s in |
| 58 | + assert_forced_to_any s' |
| 59 | + ); |
| 60 | + ] |
| 61 | + |
| 62 | +let tests = "type" >::: ["forcing_state" >::: forcing_state_tests] |
0 commit comments