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
Obj.magic with recursive modules #6005
Comments
Comment author: @garrigue Indeed, the handling of with definitions is extremely stripped down, and it looks like it was assumed than one could create concrete types with it. Unfortunately this is now possible using recursive modules. This one is easy to fix, but should look out for other problems... |
Comment author: @garrigue Fixed in trunk at revision 13647. |
Comment author: @jberdine Some of my code builds with 4.00.1 but not with trunk, and this fix is the first point where my build fails. There are several points which are affected by this, but here is a simple one. With 4.00.1 we used to be able to write a signature such as: module Arg : sig include module type of Arg with type spec := spec Note that the Set_bool case is not included in the spec type defined in the Arg module of the standard library. The type-checker used to be happy with this, but now complains: Error: This variant or record definition does not match that of type spec Is this new more restrictive behavior expected? Cheers, Josh Berdine |
Comment author: @garrigue If seems that the bug was introduced in 3.12. module type T = sig type t = A end which gives: module type T' = sig type t = u = A end Clearly the signature T' is impossible, since u has constructor B, not A. |
Comment author: @garrigue Just for the record: the same limitation is needed for destructive substitutions. module type S = sig In 3.12 and 4.00 this was accepted, and gave the invalid: module rec N : S' = N;;(N.M.A 3 :> v);;
|
Original bug ID: 6005
Reporter: @diml
Assigned to: @garrigue
Status: closed (set by @xavierleroy on 2015-12-11T18:24:05Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 4.01.0+dev
Fixed in version: 4.01.0+dev
Category: typing
Related to: #6159
Monitored by: @gasche @jberdine @alainfrisch
Bug description
It seems that consistency of module type constraints is not checked. It is then possible to write Obj.magic by converting a module type to an implementation:
let magic : type a b. a -> b = fun x ->
let module M = struct
module type A = sig type t = X of a end
type u = X of b
module type B = A with type t = u
module rec M : B = M
end in
let M.X x = M.M.X x in
x
The text was updated successfully, but these errors were encountered: