@@ -3904,6 +3904,11 @@ let subtypes = TypePairs.create 17
3904
3904
let subtype_error env trace =
3905
3905
raise (Subtype (expand_trace env (List. rev trace), [] ))
3906
3906
3907
+ let extract_concrete_typedecl_opt env t =
3908
+ match extract_concrete_typedecl env t with
3909
+ | v -> Some v
3910
+ | exception _ -> None
3911
+
3907
3912
let rec subtype_rec env trace t1 t2 cstrs =
3908
3913
let t1 = repr t1 in
3909
3914
let t2 = repr t2 in
@@ -3960,23 +3965,23 @@ let rec subtype_rec env trace t1 t2 cstrs =
3960
3965
| (Tconstr(p1 , [] , _ ), Tconstr(p2 , [] , _ )) when Path. same p1 Predef. path_int && Path. same p2 Predef. path_float ->
3961
3966
cstrs
3962
3967
| (Tconstr (path, [] , _), Tconstr (_, [] , _)) when Variant_coercion. can_coerce_primitive path &&
3963
- extract_concrete_typedecl env t2 |> Variant_coercion. can_try_coerce_variant_to_primitive |> Option. is_some
3968
+ extract_concrete_typedecl_opt env t2 |> Variant_coercion. can_try_coerce_variant_to_primitive_opt |> Option. is_some
3964
3969
->
3965
3970
(* type coercion for primitives (int/float/string) to elgible unboxed variants:
3966
3971
- must be unboxed
3967
3972
- must have a constructor case with a supported and matching primitive payload *)
3968
- (match Variant_coercion. can_try_coerce_variant_to_primitive (extract_concrete_typedecl env t2) with
3973
+ (match Variant_coercion. can_try_coerce_variant_to_primitive_opt (extract_concrete_typedecl_opt env t2) with
3969
3974
| Some (constructors , true ) ->
3970
3975
if Variant_coercion. variant_has_catch_all_case constructors (fun p -> Path. same p path) then
3971
3976
cstrs
3972
3977
else
3973
3978
(trace, t1, t2, ! univar_pairs)::cstrs
3974
3979
| _ -> (trace, t1, t2, ! univar_pairs)::cstrs)
3975
3980
| (Tconstr (_, [] , _), Tconstr (path, [] , _)) when Variant_coercion. can_coerce_primitive path &&
3976
- extract_concrete_typedecl env t1 |> Variant_coercion. can_try_coerce_variant_to_primitive |> Option. is_some
3981
+ extract_concrete_typedecl_opt env t1 |> Variant_coercion. can_try_coerce_variant_to_primitive_opt |> Option. is_some
3977
3982
->
3978
3983
(* type coercion for variants to primitives *)
3979
- (match Variant_coercion. can_try_coerce_variant_to_primitive (extract_concrete_typedecl env t1) with
3984
+ (match Variant_coercion. can_try_coerce_variant_to_primitive_opt (extract_concrete_typedecl_opt env t1) with
3980
3985
| Some (constructors , unboxed ) ->
3981
3986
if constructors |> Variant_coercion. variant_has_same_runtime_representation_as_target ~target Path:path ~unboxed then
3982
3987
cstrs
0 commit comments