Skip to content

Commit

Permalink
ocaml#9385 from lpw25/fix-copy-scope-bugs
Browse files Browse the repository at this point in the history
Fix incorrect copy_scopes in Subst

(cherry picked from commit 288bb81)
(cherry picked from commit 2e08e99)
  • Loading branch information
stedolan authored and mshinwell committed Jul 20, 2020
1 parent 4daf102 commit f4f5b98
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
39 changes: 39 additions & 0 deletions testsuite/tests/typing-modules/pr9384.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
(* TEST
* expect
*)

module M : sig
type 'a t := [< `A ] as 'a
val f : 'a -> 'a t
end = struct
let f x = x
end;;
[%%expect{|
module M : sig val f : ([< `A ] as 'a) -> 'a end
|}]

type foo = { foo : 'a. ([< `A] as 'a) -> 'a }

module Foo (X : sig type 'a t := [< `A ] as 'a type foo2 = foo = { foo : 'a. 'a t -> 'a t } end) = struct
let f { X.foo } = foo
end;;
[%%expect{|
type foo = { foo : 'a. ([< `A ] as 'a) -> 'a; }
module Foo :
functor
(X : sig type foo2 = foo = { foo : 'a. ([< `A ] as 'a) -> 'a; } end) ->
sig val f : X.foo2 -> ([< `A ] as 'a) -> 'a end
|}]

type bar = { bar : 'a. ([< `A] as 'a) -> 'a }

module Bar (X : sig type 'a t := 'a type bar2 = bar = { bar : 'a. ([< `A] as 'a) t -> 'a t } end) = struct
let f { X.bar } = bar
end;;
[%%expect{|
type bar = { bar : 'a. ([< `A ] as 'a) -> 'a; }
module Bar :
functor
(X : sig type bar2 = bar = { bar : 'a. ([< `A ] as 'a) -> 'a; } end) ->
sig val f : X.bar2 -> ([< `A ] as 'a) -> 'a end
|}]
11 changes: 6 additions & 5 deletions typing/subst.ml
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,8 @@ and signature_item' copy_scope scoping s comp =
| Sig_class_type(id, d, rs, vis) ->
Sig_class_type(id, cltype_declaration' copy_scope s d, rs, vis)

and signature_item s comp =
For_copy.with_scope (fun copy_scope -> signature_item' copy_scope s comp)
and signature_item scoping s comp =
For_copy.with_scope (fun copy_scope -> signature_item' copy_scope scoping s comp)

and module_declaration scoping s decl =
{
Expand Down Expand Up @@ -527,9 +527,10 @@ let merge_path_maps f m1 m2 =
let type_replacement s = function
| Path p -> Path (type_path s p)
| Type_function { params; body } ->
let params = List.map (type_expr s) params in
let body = type_expr s body in
Type_function { params; body }
For_copy.with_scope (fun copy_scope ->
let params = List.map (typexp copy_scope s) params in
let body = typexp copy_scope s body in
Type_function { params; body })

(* Composition of substitutions:
apply (compose s1 s2) x = apply s2 (apply s1 x) *)
Expand Down

0 comments on commit f4f5b98

Please sign in to comment.