Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007321OCamltypingpublic2016-08-05 23:132017-03-15 03:39
Assigned Togarrigue 
PlatformOSOS Version
Product Version 
Target Version4.05.0 +dev/beta1/beta2/beta3/rc1Fixed in Version4.06.0 +dev/beta1/beta2/rc1 
Summary0007321: Private type in signature clashes with type definition via functor instantiation
DescriptionConsider the following code:

module type S = sig type 'a t end
module type Sp = sig type 'a t = private 'a array end

module Id (S : S) = S

module M : Sp = struct
  include Id (struct type 'a t = 'a array end)


  (* type 'a t = 'a array *)
  (* include (Id (struct type 'a t = 'a array end) : S with type 'a t := 'a t) *)
end (* M *)

The compiler will fail with:

File "./", line 6, characters 16-288:
Error: Signature mismatch:
       Modules do not match:
         sig type 'a t = 'a array end
       is not included in
       Type declarations do not match:
         type 'a t = 'a array
       is not included in
         type 'a t = private 'a array
       File "./", line 2, characters 21-49: Expected declaration
       File "./", line 1, characters 20-29: Actual declaration
       Their variances do not agree.

This makes no sense, because the whole point of the signature is to make the type private. The included functor instantiation essentially does the same thing as establishing the type definition manually, which is just an alias anyway.

When replacing the code in module M with the second section after the comment separator, the problem goes away. The included functor instantiation doesn't really contain anything in this example then, but I have real world code where some generated functions needed to be included, along with the type, which didn't work. This signature type substitution trick can be used as a workaround for what seems to be a bug.
TagsNo tags attached.
Attached Files

- Relationships
child of 0005984confirmedgarrigue Variance information is not properly propagated through functor applications 

-  Notes
garrigue (manager)
2016-08-16 04:06

This is a direct consequence of PR#5984: since variance information is not propagated through functors, the variance assigned to the type in the output of the Id functor is insufficient.

A workaround could be to just ignore variance when one side is a normal abbreviation, and the other a private abbreviation, since their contents are guaranteed to be equal anyway.
Or are they really? Need to check the theory before doing it.
garrigue (manager)
2017-03-15 03:39

Fixed by commit 9112876.

Only check variance when the external type declaration is abstract, or when the internal type declaration is either private or an open type.
Rationale: only abstract, private and open types have an explicit variance, in other cases it is computed from the definition, so there is no need to test for inclusion separately.

- Issue History
Date Modified Username Field Change
2016-08-05 23:13 mottl New Issue
2016-08-16 04:02 garrigue Relationship added child of 0005984
2016-08-16 04:06 garrigue Note Added: 0016200
2016-08-16 04:06 garrigue Assigned To => garrigue
2016-08-16 04:06 garrigue Status new => confirmed
2016-09-27 16:24 doligez Target Version => 4.05.0 +dev/beta1/beta2/beta3/rc1
2017-02-23 16:45 doligez Category OCaml typing => typing
2017-03-15 03:39 garrigue Note Added: 0017662
2017-03-15 03:39 garrigue Status confirmed => resolved
2017-03-15 03:39 garrigue Fixed in Version => 4.06.0 +dev/beta1/beta2/rc1
2017-03-15 03:39 garrigue Resolution open => fixed

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker