Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007519OCamltypingpublic2017-04-20 20:442017-08-29 09:34
Reportermottl 
Assigned Togarrigue 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version4.04.1 
Target VersionFixed in Version4.06.0 +dev/beta1/beta2/rc1 
Summary0007519: Incorrect rejection of program due to faux scope escape
DescriptionThe following program is rejected by the compiler:

-----
module Gen_spec = struct type 't extra = unit end

module type S = sig
  module Spec : sig type 't extra = unit end

  type t
  val make : unit -> t Spec.extra
end (* S *)

module Make () : S with module Spec := Gen_spec = struct
  type t = int
  let make () = ()
end (* Make *)

let () =
  let module M = Make () in
  M.make ()
  (* (M.make () : unit) *)
-----

The error is:

-----
File "./foo.ml", line 17, characters 2-11:
Error: This expression has type M.t Gen_spec.extra = unit
       but an expression was expected of type unit
       The type constructor M.t would escape its scope
-----

The error shows that the compiler already knows that M.t Gen_spec.extra is equivalent to the unit type. Therefore, there should not be any type escaping the scope of the local module. Using the commented out last line instead of the preceding one also shows that the compiler will happily unify the type with "unit" and then accept the program.

I suppose that there is a missing conversion somewhere in the type checker that should attempt to eliminate all local types before complaining about scope violations.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0018155)
garrigue (manager)
2017-08-02 06:58

The interesting phenomenon here is that one needs to expand extra, not t, to avoid the escape.
This is nowhere in the logic of the compiler at this point.
This can be done, but the runtime cost could be significant (should check).
(0018156)
garrigue (manager)
2017-08-02 07:55

Tentative fix: https://github.com/ocaml/ocaml/pull/1273 [^]
(0018199)
garrigue (manager)
2017-08-29 09:34

Fixed by GPR#1273.

- Issue History
Date Modified Username Field Change
2017-04-20 20:44 mottl New Issue
2017-08-02 06:58 garrigue Note Added: 0018155
2017-08-02 06:58 garrigue Assigned To => garrigue
2017-08-02 06:58 garrigue Status new => confirmed
2017-08-02 07:55 garrigue Note Added: 0018156
2017-08-29 09:34 garrigue Note Added: 0018199
2017-08-29 09:34 garrigue Status confirmed => resolved
2017-08-29 09:34 garrigue Fixed in Version => 4.06.0 +dev/beta1/beta2/rc1
2017-08-29 09:34 garrigue Resolution open => fixed


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker