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

`Typemod.normalize_signature` uses wrong environment, and `Ctype.normalize_type` is not a no-op #8907

Open
lpw25 opened this issue Aug 30, 2019 · 1 comment

Comments

@lpw25
Copy link
Contributor

commented Aug 30, 2019

Typemod.normalize_signature does not populate the environment as it descends into submodules, which means that it applies Ctype.normalize_type with an environment missing local type definitions.

Ctype.normalize_type seems intended to be essentially a no-op -- it should replace one type with an equivalent, if nicer, type. However, its treatment of Reither doesn't respect type equality as defined in Ctype.eqtype.

These two facts combine to give weird behaviour that depends on whether things are in a submodule or not:

foo1.ml
type t = int

let f (x : [< `Foo of t & int & string]) = ()
foo2.ml
module M : sig
  type t = int

  let f (x : [< `Foo of t & int & string]) = ()
end
bar1.ml
include Foo1
bar2.ml
include Foo2

bar1.mli

val f : [< `Foo of int & string] -> unit

bar2.mli

module M : sig
  val f : [< `Foo of int & string] -> unit
end
$ ocamlc -c foo1.ml
$ ocamlc -c foo2.ml
$ ocamlc -c bar1.mli
$ ocamlc -c bar2.mli
$ ocamlc -c bar1.ml
$ ocamlc -c bar2.ml
File "bar2.ml", line 1:
Error: The implementation bar2.ml does not match the interface bar2.cmi:
       In module M:
       Modules do not match:
         sig type t = int val f : [< `Foo of t & int & string ] -> unit end
       is not included in
         sig val f : [< `Foo of int & string ] -> unit end
       In module M:
       Values do not match:
         val f : [< `Foo of t & int & string ] -> unit
       is not included in
         val f : [< `Foo of int & string ] -> unit
       File "bar2.mli", line 2, characters 2-42: Expected declaration
       File "foo2.ml", line 5, characters 6-7: Actual declaration

@garrigue garrigue self-assigned this Sep 2, 2019

@garrigue

This comment has been minimized.

Copy link
Contributor

commented Sep 2, 2019

Well spotted. I'll try to find a simple (and economical) fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.