Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
It seems like a hidden non-generalized type variable remains in some inferred signatures, which leads to strange errors #7601
Original bug ID: 7601
The following fragment:
module type Analysis = sig type t type 'a maybe_region = [< `Location of t | `Value of t | `None ] as 'a val of_var : ?f:string -> string -> [ `Location of _ | `Value of _ | `None ] maybe_region end module Make (Analysis : Analysis) = struct include Analysis let of_var = of_var ~f:"" end
produces the following inclusion error:
(no observable difference in types and no visible type variables) (in 4.05.0)
However, if either generalization is requested for the value `of_var' using eta-expansion or a type annotation that does not involve the type maybe_region is added, the error disappears. So either of the following works:
module Make (Analysis : Analysis) = struct include Analysis let of_var x = of_var ~f:"" x end
module Make (Analysis : Analysis) = struct include Analysis let of_var : _ -> [ `Location of _ | `None | `Value of _] = of_var ~f:"" end
module Make (Analysis : Analysis) = struct include Analysis let of_var : _ -> [ `Location of _ | `None | `Value of _] maybe_region = of_var ~f:"" end
The types like
Comment author: @garrigue
Interesting. This bug is related to the change in 4.04, where locally defined abstract types cannot be used to instantiate non-generalizable type variables once the defining module is left.
First remark: there is an easy workaround, adding a variance annotation:
type +'a maybe_region = ...
I'm thinking of a fix that wouldn't break principality for this case.