Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005914OCamlOCaml typingpublic2013-02-01 23:132013-06-22 09:37
Reportermottl 
Assigned Togarrigue 
PrioritynormalSeverityminorReproducibilityhave not tried
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version4.00.1 
Target Version4.01.0+devFixed in Version4.01.0+dev 
Summary0005914: Functor breaks with an equivalent argument signature
DescriptionValid signatures that merely differ in the order of their entries should usually be considered equivalent. But here is an example where flipping the order of two function entries in an argument signature can break a functor. It seems this is related in some bizarre way to unification of recursive types, but the behavior is just downright weird. Here is the error message when running "ocaml" on file "bug.ml" below:

File "bug.ml", line 39, characters 21-22:
Error: Signature mismatch:
       ...
       Values do not match:
         val bar : unit -> ('a M.a M.wrap as 'a)
       is not included in
         val bar : unit -> t
       File "bug.ml", line 32, characters 2-21: Expected declaration
       File "bug.ml", line 18, characters 6-9: Actual declaration

The signatures "Good" and "Bad" are clearly equivalent modulo the order of the two function entries (foo and bar). Nevertheless, the application of Func_good succeeds whereas Func_bad fails. Note that removing the signature constraint ": S" from module M will make the example pass the typechecker again, too.

----------
module type S = sig
  type 't a = [ `A ]

  type 't wrap = 't constraint 't = [> 't wrap a ]
  val foo : 't wrap -> 't wrap -> unit
end

(* module M = struct *)
module M : S = struct
  type 't a = [ `A ]
  type 't wrap = 't constraint 't = [> 't wrap a ]
  let foo x y = ()
end

module T = struct
  type t = t M.a M.wrap
  include M
  let bar : unit -> ('a M.a M.wrap as 'a) = fun () -> `A
end

include T

module type Good = sig
  type t
  val bar : unit -> t
  val foo : t -> t -> unit
end

module type Bad = sig
  type t
  val foo : t -> t -> unit
  val bar : unit -> t
end

module Func_good (Arg : Good) = struct end
module Func_bad (Arg : Bad) = struct end

module X = Func_good (T)
module Y = Func_bad (T)
----------
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0009563)
doligez (administrator)
2013-06-19 14:01

Confirmed. I'm setting 4.01.0 as the target in the hope that there is a simple fix. If this is not the case, just push it back to 4.02.
(0009594)
hnrgrgr (developer)
2013-06-21 22:14
edited on: 2013-06-21 22:23

Here is a shorter reproduction case:

-------------

type 't a = [ `A ]
type 't wrap = 't constraint 't = [> 't wrap a ]
type t = t a wrap

module T = struct
  let foo : 't wrap -> 't wrap -> unit = fun _ _ -> ()
  let bar : ('a a wrap as 'a) = `A
end

module Good : sig
  val bar: t
  val foo: t -> t -> unit
end = T

module Bad : sig
  val foo: t -> t -> unit
  val bar: t
end = T

(* One can not reproduce if 'foo' has only one parameter *)

module T' = struct
  let foo : 't wrap -> unit = fun _ -> ()
  let bar : ('a a wrap as 'a) = `A
end

module Good' : sig
  val bar: t
  val foo: t -> unit
end = T'

module Bad' : sig
  val foo: t -> unit
  val bar: t
end = T'

(0009595)
garrigue (manager)
2013-06-22 01:45

This is accepted when using ocamlc -principal.
So this seems related to the expansion-sharing optimization applied when -principal is not used.
(0009597)
garrigue (manager)
2013-06-22 09:37

Fixed in trunk and 4.01, at revision 13829 and 13830.
The row variable of polymorphic variants was not correctly instantiated in moregen_row.

- Issue History
Date Modified Username Field Change
2013-02-01 23:13 mottl New Issue
2013-04-16 12:03 gasche Severity major => minor
2013-06-19 14:01 doligez Note Added: 0009563
2013-06-19 14:01 doligez Status new => confirmed
2013-06-19 14:01 doligez Target Version => 4.01.0+dev
2013-06-21 22:14 hnrgrgr Note Added: 0009594
2013-06-21 22:17 hnrgrgr Note Edited: 0009594 View Revisions
2013-06-21 22:23 hnrgrgr Note Edited: 0009594 View Revisions
2013-06-22 01:45 garrigue Note Added: 0009595
2013-06-22 09:37 garrigue Note Added: 0009597
2013-06-22 09:37 garrigue Status confirmed => resolved
2013-06-22 09:37 garrigue Fixed in Version => 4.01.0+dev
2013-06-22 09:37 garrigue Resolution open => fixed
2013-06-22 09:37 garrigue Assigned To => garrigue


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker