ocaml-flambda / flambda-backend

The Flambda backend project for OCaml
Other
113 stars 76 forks source link

Error when printing types with `-rectypes` #3133

Open samsa1 opened 1 month ago

samsa1 commented 1 month ago

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 commented 1 month ago

The problem comes from : https://github.com/ocaml-flambda/flambda-backend/blob/95a2deeaa6523fcc96febbf998633763cce12896/ocaml/typing/oprint.ml#L513-L531 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 https://github.com/ocaml-flambda/flambda-backend/blob/95a2deeaa6523fcc96febbf998633763cce12896/ocaml/typing/printtyp.ml#L1587-L1606.

lpw25 commented 1 month ago

@riaqn You should probably have a look at this one

riaqn commented 1 month ago

Thanks - I will look next Wednesday.