Skip to content

Error when printing types with -rectypes #3133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
samsa1 opened this issue Oct 10, 2024 · 3 comments
Open

Error when printing types with -rectypes #3133

samsa1 opened this issue Oct 10, 2024 · 3 comments

Comments

@samsa1
Copy link

samsa1 commented Oct 10, 2024

I wrote a small test that fails due to a type error, however the type printing fails to an assertion failure.

(* TEST
  flags = " -rectypes ";
*)

let f (x : ((int -> 'a) as 'a)) = x

let _ = (f = 0)

Output :

File "t.ml", line 7, characters 13-14:
7 | let _ = (f = 0)
                 ^
Error: This expression has type "int" but an expression was expected of type
         "(int -> Fatal error: exception File "ocaml/typing/oprint.ml", line 531, characters 11-17: Assertion failed
@samsa1
Copy link
Author

samsa1 commented Oct 10, 2024

The problem comes from :

and print_out_ret rm ppf =
function
| Otyp_arrow _ as ty ->
begin match rm with
| Orm_not_arrow _ -> assert false
| Orm_no_parens ->
print_out_type_1 ppf ty
| Orm_parens rm ->
let m_legacy, m_new = partition_modes rm in
print_out_modes_legacy ppf m_legacy;
pp_print_char ppf '(';
print_out_type_1 ppf ty;
pp_print_char ppf ')';
print_out_modes_new ppf m_new
end
| ty ->
match rm with
| Orm_not_arrow rm -> print_out_type_mode ~arg:false rm ppf ty
| _ -> assert false
that does not handle correctly the case of Otyp_alias with recursive types.
This should maybe be corrected when computing if the next component is an arrow or not at
and tree_of_ret_typ_mutating mode acc_mode (m, ty) =
match get_desc ty with
| Tarrow _ -> begin
(* We first try to equate [m] with the [acc_mode]; if that succeeds, we
can omit parens and modes. *)
match Alloc.equate (Alloc.of_const acc_mode) m with
| Ok () ->
let ty = tree_of_typexp mode acc_mode ty in
(Orm_no_parens, ty)
| Error _ ->
(* In this branch we need to print parens. [m] might have undetermined
axes and we adopt a similar logic to the [marg] above. *)
let m = Alloc.zap_to_legacy m in
let ty = tree_of_typexp mode m ty in
(Orm_parens (tree_of_modes m), ty)
end
| _ ->
let m = Alloc.zap_to_legacy m in
let ty = tree_of_typexp mode m ty in
(Orm_not_arrow (tree_of_modes m), ty)
.

@lpw25
Copy link
Collaborator

lpw25 commented Oct 11, 2024

@riaqn You should probably have a look at this one

@riaqn
Copy link
Contributor

riaqn commented Oct 11, 2024

Thanks - I will look next Wednesday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants