Skip to content

Commit 26e8422

Browse files
committed
Minor review adjustments
1 parent 9795db4 commit 26e8422

File tree

2 files changed

+31
-27
lines changed

2 files changed

+31
-27
lines changed

ocaml/testsuite/tests/typing-modules/package_constraint.ml

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -221,31 +221,6 @@ module F :
221221
sig module M : sig type t = int end type t = M.t end
222222
|}];;
223223

224-
(* In cases where the package constraint involves a type variable from the
225-
current ty var env, it can affect inference. t1 below should check but not
226-
t2. *)
227-
module type S = sig
228-
type t : immediate
229-
end
230-
231-
type 'a t = (module S with type t = 'a)
232-
233-
type t1 = int t
234-
type t2 = string t
235-
[%%expect{|
236-
module type S = sig type t : immediate end
237-
type ('a : immediate) t = (module S with type t = 'a)
238-
type t1 = int t
239-
Line 8, characters 10-16:
240-
8 | type t2 = string t
241-
^^^^^^
242-
Error: This type string should be an instance of type ('a : immediate)
243-
The layout of string is value, because
244-
it is the primitive value type string.
245-
But the layout of string must be a sublayout of immediate, because
246-
of the definition of t at line 5, characters 0-39.
247-
|}];;
248-
249224
(* Checking such a constraint may require expanding definitions from the module
250225
being updated. *)
251226
module type S = sig
@@ -330,3 +305,28 @@ Line 1, characters 13-61:
330305
Error: In the constrained signature, type t is defined to be [< `A ].
331306
Package `with' constraints may only be used on abstract types.
332307
|}]
308+
309+
(* In cases where the package constraint involves a type variable from the
310+
current ty var env, it can affect inference. t1 below should check but not
311+
t2. *)
312+
module type S = sig
313+
type t : immediate
314+
end
315+
316+
type 'a t = (module S with type t = 'a)
317+
318+
type t1 = int t
319+
type t2 = string t
320+
[%%expect{|
321+
module type S = sig type t : immediate end
322+
type ('a : immediate) t = (module S with type t = 'a)
323+
type t1 = int t
324+
Line 8, characters 10-16:
325+
8 | type t2 = string t
326+
^^^^^^
327+
Error: This type string should be an instance of type ('a : immediate)
328+
The layout of string is value, because
329+
it is the primitive value type string.
330+
But the layout of string must be a sublayout of immediate, because
331+
of the definition of t at line 5, characters 0-39.
332+
|}];;

ocaml/typing/printtyp.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,10 @@ and labeled_type ppf (label, ty) =
622622

623623
and raw_type_list tl = raw_list raw_type tl
624624
and labeled_type_list tl = raw_list labeled_type tl
625+
and raw_lid_type_list tl =
626+
raw_list (fun ppf (lid, typ) ->
627+
fprintf ppf "(@,%a,@,%a)" longident lid raw_type typ)
628+
tl
625629
and raw_type_desc ppf = function
626630
Tvar { name; jkind } ->
627631
fprintf ppf "Tvar (@,%a,@,%s)" print_name name
@@ -678,8 +682,8 @@ and raw_type_desc ppf = function
678682
| Some(p,tl) ->
679683
fprintf ppf "Some(@,%a,@,%a)" path p raw_type_list tl)
680684
| Tpackage (p, fl) ->
681-
fprintf ppf "@[<hov1>Tpackage(@,%a@,%a)@]" path p
682-
raw_type_list (List.map snd fl)
685+
fprintf ppf "@[<hov1>Tpackage(@,%a,@,%a)@]" path p
686+
raw_lid_type_list fl
683687
and raw_row_fixed ppf = function
684688
| None -> fprintf ppf "None"
685689
| Some Types.Fixed_private -> fprintf ppf "Some Fixed_private"

0 commit comments

Comments
 (0)