Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Expand the "Unexpected existential" error message #1733
Currently when the type-checker encounters unexpected existentially quantified types, e.g.
type any = Any : 'any -> any let Any x = Any () class c (Any x) = object end class c = object(Any x) end
it emits the following errror message
If this terse message is clear from the perspective of the type-checker, it may seem mysterious from an user perspective.
This PR proposes thus to focus on the user perspective in this error message by making clear in which contexts existential types are not allowed and from where the problematic existential types come from:
let Any x = Any ()
class c (Any x) = object end
class c = object(Any x) end
The error message directly refers to an existential type name if one is available, otherwise it names the constructor itself:
type other = C: _ -> other let C x = C ()
This looks like a clear improvement.
One case that's not handled correctly yet: existential types are not allowed in
let Any _ = Any () and () = () in ()
and with this PR, the error is misreported as a problem with a toplevel binding:
This is a great point, thanks for pointing the issue. I have fixed the error message in all case where existentials are not allowed inside a local let-binding, e.g.
let () = let Any x = Any () and () = () in ()
let () = let rec Any x = Any () in ()
let () = let[@attribute] Any x = Any () in ()
class c = let Any _x = () in object end
I had a look at the code again and I realize only now that I have an implementation question: why are we exposing this somewhat-weird
Do you mean expanding the