@@ -866,7 +866,30 @@ let add_definition t (name : Name_in_binding_pos.t) kind =
866866 end ;
867867 add_symbol_definition t sym)
868868
869- let invariant_for_new_equation t name ty =
869+ let invariant_for_alias aliases name ty =
870+ (* Check that no canonical element gets an [Equals] type *)
871+ if ! Clflags. flambda_invariant_checks || true then begin
872+ match Type_grammar. get_alias_exn ty with
873+ | exception Not_found -> ()
874+ | alias ->
875+ assert (not (Simple. equal alias (Simple. name name)));
876+ let canonical =
877+ Aliases. get_canonical_ignoring_name_mode aliases name
878+ in
879+ if Simple. equal canonical (Simple. name name) then
880+ Misc. fatal_errorf
881+ " There is about to be an [Equals] equation on canonical name %a@\n equation: %a@\n @."
882+ Name. print name Type_grammar. print ty
883+ end
884+
885+ let invariant_for_aliases t =
886+ let aliases = aliases t in
887+ Name.Map. iter (fun name (ty , _ , _ ) ->
888+ invariant_for_alias aliases name ty
889+ ) (names_to_types t)
890+
891+ let invariant_for_new_equation t aliases name ty =
892+ invariant_for_alias aliases name ty;
870893 if ! Clflags. flambda_invariant_checks then begin
871894 (* CR mshinwell: This should check that precision is not decreasing. *)
872895 let defined_names =
@@ -906,7 +929,7 @@ let rec add_equation0 t aliases name ty =
906929 end
907930 end
908931 end ;
909- invariant_for_new_equation t name ty;
932+ invariant_for_new_equation t aliases name ty;
910933 let level =
911934 Typing_env_level. add_or_replace_equation
912935 (One_level. level t.current_level) name ty
@@ -940,7 +963,9 @@ let rec add_equation0 t aliases name ty =
940963 let current_level =
941964 One_level. create (current_scope t) level ~just_after_level
942965 in
943- with_current_level t ~current_level
966+ let res = with_current_level t ~current_level in
967+ invariant_for_aliases res;
968+ res
944969
945970and add_equation t name ty =
946971 if ! Clflags. flambda_invariant_checks then begin
0 commit comments