Skip to content
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

[3.07beta1] Functor typing misses constraints in a weird way #8232

Closed
vicuna opened this issue Jul 26, 2003 · 2 comments
Closed

[3.07beta1] Functor typing misses constraints in a weird way #8232

vicuna opened this issue Jul 26, 2003 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Jul 26, 2003

Original bug ID: 1780
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: Aleksey Nogin
Version: 3.07beta1
OS: Red Hat Linux
Submission from: mojave2.cs.caltech.edu (131.215.44.187)

If I create .mli and .ml with the following contents:

--- .mli ---

module type TypeSig = sig
type t
end

module Test
(Mod1: TypeSig)
(Mod2: TypeSig with type t = Mod1.t) :
(TypeSig with type t = Mod1.t)

--- end .mli ---

--- .ml ---

module type TypeSig = sig
type t
end

module Test
(Mod1: TypeSig)
(Mod2: TypeSig with type t = Mod1.t) =
struct
type t = Mod2.t
end

--- end .ml ---

Then it compiles fine with 3.06, but 3.07 beta1 does not realize that Mod1.t and
Mod2.t are really the same:

The implementation weird.ml does not match the interface weird.cmi:
Modules do not match:
functor (Mod1 : TypeSig) ->
functor (Mod2 : sig type t = Mod1.t end) -> sig type t = Mod2.t end
is not included in
functor (Mod1 : TypeSig) ->
functor (Mod2 : sig type t = Mod1.t end) -> sig type t = Mod1.t end
Modules do not match:
functor (Mod2 : sig type t = Mod1.t end) -> sig type t = Mod2.t end
is not included in
functor (Mod2 : sig type t = Mod1.t end) -> sig type t = Mod1.t end
Modules do not match:
sig type t = Mod2.t end
is not included in
sig type t = Mod1.t end
Type declarations do not match:
type t = Mod2.t
is not included in
type t = Mod1.t

Note that this works correctly "locally" - if I add an explicit signature to the
.ml file :

--- different .ml ---

module type TypeSig = sig
type t
end

module Test
(Mod1: TypeSig)
(Mod2: TypeSig with type t = Mod1.t) :
(TypeSig with type t = Mod1.t) =
struct
type t = Mod2.t
end

--- end different .ml ---

then it compiles fine. Still, this is pretty annoying as it breaks existing code
in a way that takes a while to figure out and fix.

@vicuna
Copy link
Author

vicuna commented Jul 29, 2003

Comment author: administrator

[Failed functor type matching]

Still, this is pretty annoying as it breaks existing code in a way
that takes a while to figure out and fix.

Don't change your code -- it's a bug on my side. The functor
subtyping rule was changed to match the theory (the implemented rule
was unnecessarily restrictive), but a (lack of) substitution bug crept up.
Below is a patch that fixes this issue.

Thanks for reporting this bug.

  • Xavier Leroy

Index: csl/typing/includemod.ml
diff -c csl/typing/includemod.ml:1.31 csl/typing/includemod.ml:1.32
*** csl/typing/includemod.ml:1.31 Fri Jul 18 14:44:18 2003
--- csl/typing/includemod.ml Sun Jul 27 19:02:33 2003


*** 10,16 ****
(* *)
(***********************************************************************)

! (* $Id: includemod.ml,v 1.31 2003/07/18 12:44:18 xleroy Exp $ *)

(* Inclusion checks for the module language *)

--- 10,16 ----
(* *)
(***********************************************************************)

! (* $Id: includemod.ml,v 1.32 2003/07/27 17:02:33 xleroy Exp $ *)

(* Inclusion checks for the module language *)


*** 147,159 ****
| (Tmty_signature sig1, Tmty_signature sig2) ->
signatures env subst sig1 sig2
| (Tmty_functor(param1, arg1, res1), Tmty_functor(param2, arg2, res2)) ->
! let cc_arg =
! modtypes env Subst.identity (Subst.modtype subst arg2) arg1
! in
let cc_res =
! modtypes (Env.add_module param1 arg2 env)
! (Subst.add_module param2 (Pident param1) subst) res1 res2
! in
begin match (cc_arg, cc_res) with
(Tcoerce_none, Tcoerce_none) -> Tcoerce_none
| _ -> Tcoerce_functor(cc_arg, cc_res)
--- 147,157 ----
| (Tmty_signature sig1, Tmty_signature sig2) ->
signatures env subst sig1 sig2
| (Tmty_functor(param1, arg1, res1), Tmty_functor(param2, arg2, res2)) ->
! let arg2' = Subst.modtype subst arg2 in
! let cc_arg = modtypes env Subst.identity arg2' arg1 in
let cc_res =
! modtypes (Env.add_module param1 arg2' env)
! (Subst.add_module param2 (Pident param1) subst) res1 res2 in
begin match (cc_arg, cc_res) with
(Tcoerce_none, Tcoerce_none) -> Tcoerce_none
| _ -> Tcoerce_functor(cc_arg, cc_res)

@vicuna
Copy link
Author

vicuna commented Jul 29, 2003

Comment author: administrator

Fixed 2003-07-28 by XL

@vicuna vicuna closed this as completed Jul 29, 2003
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant