-
Notifications
You must be signed in to change notification settings - Fork 455
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
Allow free vars in types for coercion. #6828
Conversation
There are two forms of type coercion: 1 `e: t0 :> t` 2 `e :> t` The first form was never supported in .res syntax, and is now removed from parsed and typed tree. That said, coercion 1 is the only one that ever supported coercion with free variables. So this is subject to more investigation. See #6828
So, this enables you to use free variables when coercing...? I guess I don't fully understand the change. |
This just disables the check for free variables. |
I wonder what types of issues it could cause.. |
Tried to run all tests in the ocaml repo, and they work after this change. Here's a bunch of new things that type check: module NoFreeVars = {
type t = private int
let f = (x: t) => (x :> int)
let g = (y: t) => ()
let h = x => (g(x), (x :> int))
let h2 = x => ((x :> int), g(x))
}
module WithTypeArg = {
type t<'a> = private int
let f = (x: t<_>) => (x :> int)
}
module FunctionType = {
type t = private int
let f = _ => (Obj.magic(3) : t)
let _ = f :> (_ => int)
}
module Contravariant = {
type t = private int
let f1 = (_:int) => ()
let _ = f1 :> (t => unit)
let f2 = (_:int, _) => ()
let _ = f2 :> ((t, _) => unit)
}
module Totallypoly = {
let f = x => (x :> int)
let idint = (x:int) => x
let _ = f == idint
} |
915cf36
to
16ae754
Compare
There are two forms of type coercion: 1 `e: t0 :> t` 2 `e :> t` The first form was never supported in .res syntax, and is now removed from parsed and typed tree. That said, coercion 1 is the only one that ever supported coercion with free variables. So this is subject to more investigation. See #6828
…6829) * Remove coercion with 2 types, which is only supported in ml syntax. There are two forms of type coercion: 1 `e: t0 :> t` 2 `e :> t` The first form was never supported in .res syntax, and is now removed from parsed and typed tree. That said, coercion 1 is the only one that ever supported coercion with free variables. So this is subject to more investigation. See #6828 * Cleanup and indent. * Make Texp_coerce compatible with old runtime representation. By adding a unit argument to the payload.
See #6821 Free variables are not allowed in coercion, and if that happens, simple unification is performed without ever attempting coercion. This seems to go back a very long time. There's probably a good reason why free vars were not allowed. At the same time, there are no objects/classes supported in the language anymore, so it's not clear how those reasons would adapt. This just marks the place where one could investigate.
3312be7
to
7a4b87f
Compare
See #6821
Free variables are not allowed in coercion, and if that happens, simple unification is performed without ever attempting coercion. This seems to go back a very long time.
There's probably a good reason why free vars were not allowed. At the same time, there are no objects/classes supported in the language anymore, so it's not clear how those reasons would adapt.
This just marks the place where one could investigate.