Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007601OCamltypingpublic2017-07-31 16:272017-09-13 01:35
Reportermandrykin 
Assigned Togarrigue 
PrioritylowSeverityminorReproducibilityalways
StatusresolvedResolutionfixed 
Platformx86_64OSLinux 4.4.0OS VersionUbuntu 16.04.2
Product Version4.05.0 
Target VersionFixed in Version4.06.0+dev 
Summary0007601: It seems like a hidden non-generalized type variable remains in some inferred signatures, which leads to strange errors
DescriptionThe following fragment:

module type Analysis = sig
  type t
  type 'a maybe_region =
    [< `Location of t
    | `Value of t
    | `None ] as 'a
  val of_var : ?f:string -> string -> [ `Location of _ | `Value of _ | `None ] maybe_region
end

module Make (Analysis : Analysis) = struct
  include Analysis
  let of_var = of_var ~f:""
end

produces the following inclusion error:

At position module Make(Analysis) : <here> Values do not match:
         val of_var : string -> [ `Location of t | `None | `Value of t ]
       is not included in
         val of_var : string -> [ `Location of t | `None | `Value of t ]

(no observable difference in types and no visible type variables) (in 4.05.0)

However, if either generalization is requested for the value `of_var' using eta-expansion or a type annotation that does *not* involve the type maybe_region is added, the error disappears. So either of the following works:

module Make (Analysis : Analysis) = struct
  include Analysis
  let of_var x = of_var ~f:"" x
end

or

module Make (Analysis : Analysis) = struct
  include Analysis
  let of_var : _ -> [ `Location of _ | `None | `Value of _] = of_var ~f:""
end

but not

module Make (Analysis : Analysis) = struct
  include Analysis
  let of_var : _ -> [ `Location of _ | `None | `Value of _] maybe_region = of_var ~f:""
end
Additional InformationThe types like [`A of _ | `B of _ | `C] t where 'a t = 'a constraint 'a = [`A of t1 | `B of t2 | `C of t3 | `D of ... | .... | `X of tn] are convenient for avoiding repeating the types of the polymorphic constructors if they are taken from some pre-defined set e.g. using
[`Location of _ | `None] maybe_region instead of
[`Location of U.t * [`None | `Value of U.t] | `None].
TagsNo tags attached.
Attached Files? file icon slice.ml [^] (857 bytes) 2017-07-31 16:27 [Show Content]
? file icon example.ml [^] (371 bytes) 2017-07-31 16:58 [Show Content]

- Relationships

-  Notes
(0018148)
mandrykin (reporter)
2017-07-31 16:59

Added another more minimal example, the presence of an abstract type among the types of constructors does also matter.
(0018151)
garrigue (manager)
2017-08-02 03:40

Interesting. This bug is related to the change in 4.04, where locally defined abstract types cannot be used to instantiate non-generalizable type variables once the defining module is left.

First remark: there is an easy workaround, adding a variance annotation:

  type +'a maybe_region = ...

I'm thinking of a fix that wouldn't break principality for this case.
(0018152)
garrigue (manager)
2017-08-02 04:25

Tentative fix: https://github.com/ocaml/ocaml/pull/1272 [^]
(0018200)
garrigue (manager)
2017-08-29 10:44

Fixed in 4.05 branch after 4.05.0 by GPR#1272.

Note that the fix requires copying signatures, which seems to increase the size of cmi's when there is no mli.
(0018232)
garrigue (manager)
2017-09-06 14:45

Fix was breaking camomille and Frama-C. Reverted it.
(0018233)
garrigue (manager)
2017-09-06 16:05

New tentative fix: https://github.com/ocaml/ocaml/pull/1320 [^]
(0018242)
garrigue (manager)
2017-09-13 01:35

Fixed in trunk by commit ab7af2aa, by replacing row variables of static variant types with Tnil.

- Issue History
Date Modified Username Field Change
2017-07-31 16:27 mandrykin New Issue
2017-07-31 16:27 mandrykin File Added: slice.ml
2017-07-31 16:58 mandrykin File Added: example.ml
2017-07-31 16:59 mandrykin Note Added: 0018148
2017-08-02 03:40 garrigue Note Added: 0018151
2017-08-02 03:40 garrigue Assigned To => garrigue
2017-08-02 03:40 garrigue Status new => assigned
2017-08-02 04:25 garrigue Note Added: 0018152
2017-08-29 10:44 garrigue Note Added: 0018200
2017-08-29 10:44 garrigue Status assigned => resolved
2017-08-29 10:44 garrigue Fixed in Version => 4.06.0+dev
2017-08-29 10:44 garrigue Resolution open => fixed
2017-09-06 14:45 garrigue Note Added: 0018232
2017-09-06 14:45 garrigue Status resolved => confirmed
2017-09-06 16:05 garrigue Note Added: 0018233
2017-09-13 01:35 garrigue Note Added: 0018242
2017-09-13 01:35 garrigue Status confirmed => resolved


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker