Skip to content

Commit

Permalink
create type hole to see which tests fail
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn committed May 6, 2024
1 parent 0adc110 commit 01610e5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/core/tUnification.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type unification_context = {
equality_kind : eq_kind;
equality_underlying : bool;
strict_field_kind : bool;
type_param_pairs : (typed_type_param * typed_type_param) list ref option;
}

type unify_min_result =
Expand All @@ -64,6 +65,7 @@ let default_unification_context = {
equality_kind = EqStrict;
equality_underlying = false;
strict_field_kind = false;
type_param_pairs = None;
}

(* Unify like targets (e.g. Java) probably would. *)
Expand All @@ -75,6 +77,7 @@ let native_unification_context = {
equality_underlying = false;
allow_arg_name_mismatch = true;
strict_field_kind = false;
type_param_pairs = None;
}

module Monomorph = struct
Expand Down Expand Up @@ -575,6 +578,14 @@ let rec type_eq uctx a b =
| TEnum (e1,tl1) , TEnum (e2,tl2) ->
if e1 != e2 && not (param = EqCoreType && e1.e_path = e2.e_path) then error [cannot_unify a b];
type_eq_params uctx a b tl1 tl2
| TInst ({cl_kind = KTypeParameter ttp1},tl1) , TInst ({cl_kind = KTypeParameter ttp2},tl2) when uctx.type_param_pairs <> None ->
let pairs = Option.get uctx.type_param_pairs in
begin try
let ttp3 = List.assq ttp1 !pairs in
if ttp2 != ttp3 then error [cannot_unify a b]
with Not_found ->
pairs := (ttp1,ttp2) :: !pairs
end
| TInst (c1,tl1) , TInst (c2,tl2) ->
if c1 != c2 && not (param = EqCoreType && c1.cl_path = c2.cl_path) && (match c1.cl_kind, c2.cl_kind with KExpr _, KExpr _ -> false | _ -> true) then error [cannot_unify a b];
type_eq_params uctx a b tl1 tl2
Expand Down Expand Up @@ -732,6 +743,14 @@ let rec unify (uctx : unification_context) a b =
unify_to {uctx with allow_transitive_cast = false} a b ab tl
| TAbstract (a1,tl1) , TAbstract (a2,tl2) ->
unify_abstracts uctx a b a1 tl1 a2 tl2
| TInst ({cl_kind = KTypeParameter ttp1},tl1) , TInst ({cl_kind = KTypeParameter ttp2},tl2) when uctx.type_param_pairs <> None ->
let pairs = Option.get uctx.type_param_pairs in
begin try
let ttp3 = List.assq ttp1 !pairs in
if ttp2 != ttp3 then error [cannot_unify a b]
with Not_found ->
pairs := (ttp1,ttp2) :: !pairs
end
| TInst (c1,tl1) , TInst (c2,tl2) ->
let rec loop c tl =
if c == c2 then begin
Expand Down
1 change: 1 addition & 0 deletions src/typing/tanon_identification.ml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ object(self)
equality_kind = EqStricter;
equality_underlying = false;
strict_field_kind = true;
type_param_pairs = None;
} else {default_unification_context with equality_kind = EqDoNotFollowNull} in

let check () =
Expand Down
7 changes: 4 additions & 3 deletions src/typing/typeloadCheck.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,17 @@ let is_generic_parameter ctx c =
false

let valid_redefinition map1 map2 f1 t1 f2 t2 = (* child, parent *)
let uctx = {default_unification_context with type_param_pairs = Some (ref [])} in
let valid t1 t2 =
Type.unify t1 t2;
unify_custom uctx t1 t2;
if is_null t1 <> is_null t2 || ((follow t1) == t_dynamic && (follow t2) != t_dynamic) then raise (Unify_error [Cannot_unify (t1,t2)]);
in
begin match PurityState.get_purity_from_meta f2.cf_meta,PurityState.get_purity_from_meta f1.cf_meta with
| PurityState.Pure,PurityState.MaybePure -> f1.cf_meta <- (Meta.Pure,[EConst(Ident "expect"),f2.cf_pos],null_pos) :: f1.cf_meta
| PurityState.ExpectPure p,PurityState.MaybePure -> f1.cf_meta <- (Meta.Pure,[EConst(Ident "expect"),p],null_pos) :: f1.cf_meta
| _ -> ()
end;
let t1, t2 = (match f1.cf_params, f2.cf_params with
(* let t1, t2 = (match f1.cf_params, f2.cf_params with
| [], [] -> t1, t2
| l1, l2 when List.length l1 = List.length l2 ->
let to_check = ref [] in
Expand Down Expand Up @@ -89,7 +90,7 @@ let valid_redefinition map1 map2 f1 t1 f2 t2 = (* child, parent *)
| _ ->
(* ignore type params, will create other errors later *)
t1, t2
) in
) in *)
match f1.cf_kind,f2.cf_kind with
| Method m1, Method m2 when not (m1 = MethDynamic) && not (m2 = MethDynamic) ->
begin match follow t1, follow t2 with
Expand Down

0 comments on commit 01610e5

Please sign in to comment.