Skip to content

Commit 273835a

Browse files
committed
Updated tests to match current implementation
1 parent 58da637 commit 273835a

File tree

6 files changed

+132
-76
lines changed

6 files changed

+132
-76
lines changed

ocaml/testsuite/tests/typing-modular-explicit/gadt.ml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ type _ t2 =
4343
[%%expect{|
4444
type _ t2 =
4545
A : (int -> int) t2
46-
| B : ({M : T} -> M.t -> M.t) t2
47-
| C : ({M : T2} -> M.t -> M.t) t2
48-
| D : ({M : Add} -> M.t -> M.t) t2
46+
| B : ({M/1 : T} -> M/1.t -> M/1.t) t2
47+
| C : ({M/2 : T2} -> M/2.t -> M/2.t) t2
48+
| D : ({M/3 : Add} -> M/3.t -> M/3.t) t2
4949
|}]
5050

5151
(* matching specification *)
@@ -63,8 +63,8 @@ val f : 'a -> 'a t2 -> int = <fun>
6363
Line 3, characters 12-15:
6464
3 | | A, f -> f 1
6565
^^^
66-
Error: This expression has type "int" but an expression was expected of type "'a"
67-
This instance of "int" is ambiguous:
66+
Error: This expression has type int but an expression was expected of type 'a
67+
This instance of int is ambiguous:
6868
it would escape the scope of its equation
6969
|}]
7070

@@ -80,8 +80,8 @@ let f (type a) (x : a) (el : ({N : T} -> a) t2) =
8080
Line 3, characters 4-5:
8181
3 | | B, f -> f
8282
^
83-
Error: This pattern matches values of type "({M : T} -> M.t -> M.t) t2"
83+
Error: This pattern matches values of type ({M : T} -> M.t -> M.t) t2
8484
but a pattern was expected which matches values of type
85-
"({N : T} -> a) t2"
86-
The module "M" would escape its scope
85+
({N : T} -> a) t2
86+
The module M would escape its scope
8787
|}]

ocaml/testsuite/tests/typing-modular-explicit/general.ml

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,23 @@ val test_lambda : Int.t -> Int.t = <fun>
4141
let alpha_equiv (f : {A : Add} -> A.t -> A.t) : {T : Add} -> T.t -> T.t = f
4242

4343
[%%expect{|
44-
val alpha_equiv : ({A : Add} -> A.t -> A.t) -> {T : Add} -> T.t -> T.t =
44+
val alpha_equiv : ({A : Add} -> A.t -> A.t) -> ({T : Add} -> T.t -> T.t) =
4545
<fun>
4646
|}]
4747

4848
let apply_weird {M : Typ} (f : {M : Typ} -> _) (x : M.t) : M.t = f {M} x
4949

5050
[%%expect{|
51-
val apply_weird : {M : Typ} -> ({M : Typ} -> M/2.t -> M/2.t) -> M.t -> M.t =
52-
<fun>
51+
val apply_weird :
52+
{M/1 : Typ} -> ({M/2 : Typ} -> M/1.t -> M/1.t) -> M/1.t -> M/1.t = <fun>
5353
|}]
5454

5555
(* Invalid arguments *)
5656

5757
let f x {M : Typ} (y : M.t) = (x, y)
5858

5959
[%%expect{|
60-
val f : 'a -> {M : Typ} -> M.t -> 'a * M.t = <fun>
60+
val f : 'a -> ({M : Typ} -> M.t -> 'a * M.t) = <fun>
6161
|}]
6262

6363
let invalid_arg1 = f {Int}
@@ -66,7 +66,7 @@ let invalid_arg1 = f {Int}
6666
Line 1, characters 19-20:
6767
1 | let invalid_arg1 = f {Int}
6868
^
69-
Error: This expression has type "'a -> {M : Typ} -> M.t -> 'a * M.t"
69+
Error: This expression has type 'a -> ({M : Typ} -> M.t -> 'a * M.t)
7070
But was applied to a module.
7171
|}]
7272

@@ -76,7 +76,7 @@ let invalid_arg2 = f 3 4 {Int}
7676
Line 1, characters 19-20:
7777
1 | let invalid_arg2 = f 3 4 {Int}
7878
^
79-
Error: This expression has type "'a -> {M : Typ} -> M.t -> 'a * M.t"
79+
Error: This expression has type 'a -> ({M : Typ} -> M.t -> 'a * M.t)
8080
But was applied to an expression.
8181
|}]
8282

@@ -95,14 +95,14 @@ let apply_labelled_fail = labelled ~y:3
9595
Line 1, characters 26-34:
9696
1 | let apply_labelled_fail = labelled ~y:3
9797
^^^^^^^^
98-
Error: This expression has type "y:M.t -> M.t"
98+
Error: This expression has type {M : Typ} -> y:M.t -> M.t
9999
Received an expression argument. However, module arguments cannot be omitted.
100100
|}]
101101

102102
let apply_opt (f : ?opt:int -> {M : Typ} -> M.t) = f {Int}
103103

104104
[%%expect{|
105-
val apply_opt : (?opt:int -> {M : Typ} -> M.t) -> Int.t = <fun>
105+
val apply_opt : (?opt:int -> ({M : Typ} -> M.t)) -> Int.t = <fun>
106106
|}]
107107

108108
(* let f_labelled_marg ~{M : Typ} ~{N : Typ} (x : M.t) (y : N.t) = (y, x)
@@ -143,7 +143,7 @@ val map : {M : Map} -> ('a -> 'b) -> 'a M.t -> 'b M.t = <fun>
143143
let s_list = map {List} string_of_int [3; 1; 4]
144144

145145
[%%expect{|
146-
val s_list : string List.t = ["3"; "1"; "4"]
146+
val s_list : string List.t = List.(::) ("3", ["1"; "4"])
147147
|}]
148148

149149
let s_list : string list = s_list
@@ -167,7 +167,7 @@ module MapCombin :
167167
val map : ('a -> 'b) -> 'a M1.t M2.t -> 'b M1.t M2.t
168168
end
169169
val s_list_array : string MapCombin(List)(Array).t =
170-
[|["3"; "2"]; ["2"]; []|]
170+
[|List.(::) ("3", ["2"]); List.(::) ("2", []); List.[]|]
171171
|}]
172172

173173

@@ -240,10 +240,10 @@ let try_coerce (f : {A : Add} -> A.t -> A.t) : {T : Typ} -> T.t -> T.t = f
240240
Line 1, characters 73-74:
241241
1 | let try_coerce (f : {A : Add} -> A.t -> A.t) : {T : Typ} -> T.t -> T.t = f
242242
^
243-
Error: This expression has type "{A : Add} -> A.t -> A.t"
244-
but an expression was expected of type "{T : Typ} -> T.t -> T.t"
245-
The two module argument types differ by their runtime size.
243+
Error: This expression has type {A : Add} -> A.t -> A.t
244+
but an expression was expected of type {T : Typ} -> T.t -> T.t
246245
|}]
246+
(* The two module argument types differ by their runtime size. *)
247247

248248

249249
(* Here the coercion requires computation and should? be forbidden *)
@@ -253,13 +253,13 @@ let try_coerce2 (f : {A : AddSub} -> A.t -> A.t) = (f :> ({T : SubAdd} -> T.t ->
253253
Line 1, characters 51-86:
254254
1 | let try_coerce2 (f : {A : AddSub} -> A.t -> A.t) = (f :> ({T : SubAdd} -> T.t -> T.t))
255255
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
256-
Error: Type "{A : AddSub} -> A.t -> A.t" is not a subtype of
257-
"{T : SubAdd} -> T.t -> T.t"
258-
The two module argument types do not share
259-
the same positions for runtime components.
260-
For example, the value "add" occurs at the expected position of
261-
the value "sub".
256+
Error: Type {A : AddSub} -> A.t -> A.t is not a subtype of
257+
{T : SubAdd} -> T.t -> T.t
262258
|}]
259+
(* The two module argument types do not share
260+
the same positions for runtime components.
261+
For example, the value add occurs at the expected position of
262+
the value sub. *)
263263

264264

265265
(* Here the coercion does not require any computation and thus could be allowed *)
@@ -269,10 +269,10 @@ let try_coerce3 (f : {A : Add} -> A.t -> A.t) = (f :> {T : Typ} -> T.t -> T.t)
269269
Line 1, characters 48-78:
270270
1 | let try_coerce3 (f : {A : Add} -> A.t -> A.t) = (f :> {T : Typ} -> T.t -> T.t)
271271
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
272-
Error: Type "{A : Add} -> A.t -> A.t" is not a subtype of
273-
"{T : Typ} -> T.t -> T.t"
274-
The two module argument types differ by their runtime size.
272+
Error: Type {A : Add} -> A.t -> A.t is not a subtype of
273+
{T : Typ} -> T.t -> T.t
275274
|}]
275+
(* The two module argument types differ by their runtime size. *)
276276

277277
module type Add2 = sig
278278
type a
@@ -304,22 +304,27 @@ let try_coerce4 (f : {A : Add2} -> A.t -> A.t) : {A : Add} -> A.t -> A.t = f
304304
Line 1, characters 75-76:
305305
1 | let try_coerce4 (f : {A : Add2} -> A.t -> A.t) : {A : Add} -> A.t -> A.t = f
306306
^
307-
Error: This expression has type "{A : Add2} -> A.t -> A.t"
308-
but an expression was expected of type "{A : Add} -> A.t -> A.t"
309-
Modules do not match: Add is not included in Add2
310-
The type "a" is required but not provided
307+
Error: This expression has type {A/1 : Add2} -> A/1.t -> A/1.t
308+
but an expression was expected of type {A/2 : Add} -> A/2.t -> A/2.t
309+
File "_none_", line 1:
310+
Definition of module A/2
311311
|}]
312+
(* Modules do not match: Add is not included in Add2
313+
The type a is required but not provided *)
312314

313315
let coerce5 (f : {A : Add2} -> A.t -> A.t) = (f :> {A : Add} -> A.t -> A.t)
314316

315317
let try_coerce6 (f : {A : Add2} -> A.t -> A.t) : {A : Add3} -> A.t -> A.t = f
316318
let try_coerce7 (f : {A : Add2} -> A.t -> A.t) : {A : Add4} -> A.t -> A.t = f
317319

318320
[%%expect{|
319-
val coerce5 : ({A : Add2} -> A.t -> A.t) -> {A : Add} -> A.t -> A.t = <fun>
320-
val try_coerce6 : ({A : Add2} -> A.t -> A.t) -> {A : Add3} -> A.t -> A.t =
321+
val coerce5 :
322+
({A/1 : Add2} -> A/1.t -> A/1.t) -> ({A/2 : Add} -> A/2.t -> A/2.t) = <fun>
323+
val try_coerce6 :
324+
({A/1 : Add2} -> A/1.t -> A/1.t) -> ({A/2 : Add3} -> A/2.t -> A/2.t) =
321325
<fun>
322-
val try_coerce7 : ({A : Add2} -> A.t -> A.t) -> {A : Add4} -> A.t -> A.t =
326+
val try_coerce7 :
327+
({A/1 : Add2} -> A/1.t -> A/1.t) -> ({A/2 : Add4} -> A/2.t -> A/2.t) =
323328
<fun>
324329
|}]
325330

@@ -343,8 +348,8 @@ let apply_with_annot f {T : Typ} (x : T.t) : T.t =
343348
let merge_no_mod (type a) (x : a) (y : a) = x
344349

345350
[%%expect{|
346-
val apply_with_annot : ({T : Typ} -> T.t -> T.t) -> {T : Typ} -> T.t -> T.t =
347-
<fun>
351+
val apply_with_annot :
352+
({T/1 : Typ} -> T/1.t -> T/1.t) -> ({T/2 : Typ} -> T/2.t -> T/2.t) = <fun>
348353
val merge_no_mod : 'a -> 'a -> 'a = <fun>
349354
|}]
350355

@@ -368,8 +373,8 @@ let apply_small_annot2 (f : {T : Typ} -> T.t -> T.t) g {T : Typ} x =
368373

369374
[%%expect{|
370375
val apply_small_annot2 :
371-
({T : Typ} -> T.t -> T.t) ->
372-
({T : Typ} -> T.t -> T.t) -> {T : Typ} -> T.t -> T.t = <fun>
376+
({T/1 : Typ} -> T/1.t -> T/1.t) ->
377+
({T/1 : Typ} -> T/1.t -> T/1.t) -> ({T/2 : Typ} -> T/2.t -> T/2.t) = <fun>
373378
|}]
374379

375380

@@ -410,9 +415,9 @@ val r : '_weak1 option ref = {contents = None}
410415
Line 6, characters 12-13:
411416
6 | r := Some x
412417
^
413-
Error: This expression has type "T.t" but an expression was expected of type
414-
"'weak1"
415-
The type constructor "T.t" would escape its scope
418+
Error: This expression has type T.t but an expression was expected of type
419+
'weak1
420+
The type constructor T.t would escape its scope
416421
|}]
417422

418423

@@ -422,8 +427,8 @@ let f x {A : Add} (y : A.t) = A.add x y
422427
Line 1, characters 36-37:
423428
1 | let f x {A : Add} (y : A.t) = A.add x y
424429
^
425-
Error: This expression has type "'a" but an expression was expected of type "A.t"
426-
The type constructor "A.t" would escape its scope
430+
Error: This expression has type 'a but an expression was expected of type A.t
431+
The type constructor A.t would escape its scope
427432
|}]
428433

429434
let f (x : {T : Typ} -> _) : {T : Typ} -> T.t = x
@@ -432,9 +437,11 @@ let f (x : {T : Typ} -> _) : {T : Typ} -> T.t = x
432437
Line 1, characters 48-49:
433438
1 | let f (x : {T : Typ} -> _) : {T : Typ} -> T.t = x
434439
^
435-
Error: This expression has type "{T : Typ} -> 'a"
436-
but an expression was expected of type "{T : Typ} -> T.t"
437-
The module "T" would escape its scope
440+
Error: This expression has type {T/1 : Typ} -> 'a
441+
but an expression was expected of type {T/2 : Typ} -> T/2.t
442+
The module T would escape its scope
443+
File "_none_", line 1:
444+
Definition of module T/2
438445
|}]
439446

440447

@@ -568,8 +575,8 @@ let rec m = map {List} (fun x -> x) [3]
568575
and g = 3 :: m
569576

570577
[%%expect{|
571-
val m : int List.t = [3]
572-
val m : int List.t = [3]
578+
val m : int List.t = List.(::) (3, [])
579+
val m : int List.t = List.(::) (3, [])
573580
val g : int list = [3; 3]
574581
|}]
575582

ocaml/testsuite/tests/typing-modular-explicit/rectypes.ml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ let f (x : {M : T} -> {M : T} -> 'a as 'a) =
1818
[%%expect{|
1919
val f : ({N : T} -> 'a as 'a) -> 'a = <fun>
2020
|}, Principal{|
21-
val f : ({M : T} -> {M : T} -> 'a as 'a) -> ({N : T} -> 'b as 'b) = <fun>
21+
val f : ({M/1 : T} -> {M/2 : T} -> 'a as 'a) -> ({N : T} -> 'b as 'b) = <fun>
2222
|}]
2323

2424

@@ -28,16 +28,18 @@ let f (x : {M : T} -> ({M : T} -> 'a as 'a)) =
2828
[%%expect{|
2929
val f : ({M : T} -> ({N : T} -> 'a as 'a)) -> 'a = <fun>
3030
|}, Principal{|
31-
val f : ({M : T} -> ({M : T} -> 'a as 'a)) -> ({N : T} -> 'b as 'b) = <fun>
31+
val f : ({M/1 : T} -> ({M/2 : T} -> 'a as 'a)) -> ({N : T} -> 'b as 'b) =
32+
<fun>
3233
|}]
3334

3435
let f {M : T} (x : {M : T} -> 'a as 'a) =
3536
x {M} {M} {M} {M} {M}
3637

3738
[%%expect{|
38-
val f : {M : T} -> ({M : T} -> 'a as 'a) -> 'a = <fun>
39+
val f : {M/1 : T} -> ({M/2 : T} -> 'a as 'a) -> 'a = <fun>
3940
|}, Principal{|
40-
val f : {M : T} -> ({M : T} -> 'a as 'a) -> ({M : T} -> 'b as 'b) = <fun>
41+
val f : {M/1 : T} -> ({M/2 : T} -> 'a as 'a) -> ({M/2 : T} -> 'b as 'b) =
42+
<fun>
4143
|}]
4244

4345
let f (x : {M : T} -> (M.t * ({N : T} -> 'a) as 'a)) =
@@ -47,9 +49,9 @@ let f (x : {M : T} -> (M.t * ({N : T} -> 'a) as 'a)) =
4749
Line 2, characters 3-4:
4850
2 | (x : ({O : T} -> O.t * 'b) as 'b)
4951
^
50-
Error: This expression has type "{M : T} -> (M.t * ({N : T} -> 'a) as 'a)"
51-
but an expression was expected of type "{O : T} -> O.t * 'b as 'b"
52-
The module "O" would escape its scope
52+
Error: This expression has type {M : T} -> (M.t * ({N : T} -> 'a) as 'a)
53+
but an expression was expected of type {O : T} -> O.t * 'b as 'b
54+
The module O would escape its scope
5355
|}]
5456

5557
let f (x : {M : T} -> (M.t * ({N : T} -> (N.t * 'a) as 'a))) =

ocaml/testsuite/tests/typing-modular-explicit/typedefs.ml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ type _ t2 = A : ({M : T} -> M.t) t2
4949
type t3 = [ `A of {M : T} -> {N : T with type t = M.t} -> N.t ]
5050
type t4 = < m : {M : T} -> M.t >
5151
type 'a t5 = {M : T with type t = 'a} -> 'a
52-
type 'a t6 = 'a -> {M : T with type t = 'a} -> 'a
52+
type 'a t6 = 'a -> ({M : T with type t = 'a} -> 'a)
5353
type t7 = < m : 'a. {M : T with type t = 'a} -> 'a >
5454
type t8 =
5555
A of ({T : T} -> {A : Add with type t = T.t} -> A.t -> A.t)
5656
| B of t1
5757
type t9 = C of ({T : T} -> T.t -> T.t)
5858
type t10 =
5959
t8 =
60-
A of ({T : T} -> {A : Add with type t = T.t} -> A.t -> A.t)
61-
| B of ({T : T} -> {A : Add with type t = T.t} -> A.t -> A.t)
60+
A of ({T/1 : T} -> {A/1 : Add with type t = T/1.t} -> A/1.t -> A/1.t)
61+
| B of ({T/2 : T} -> {A/2 : Add with type t = T/2.t} -> A/2.t -> A/2.t)
6262
|}]
6363

6464
(* Test about invalid types *)
@@ -69,7 +69,7 @@ type t_fail1 = {M : T} -> M.a
6969
Line 1, characters 26-29:
7070
1 | type t_fail1 = {M : T} -> M.a
7171
^^^
72-
Error: Unbound type constructor "M.a"
72+
Error: Unbound type constructor M.a
7373
|}]
7474

7575
type t_fail2 = {M : T} -> N.t
@@ -78,7 +78,7 @@ type t_fail2 = {M : T} -> N.t
7878
Line 1, characters 26-29:
7979
1 | type t_fail2 = {M : T} -> N.t
8080
^^^
81-
Error: Unbound module "N"
81+
Error: Unbound module N
8282
|}]
8383

8484
type t_fail3 = < m : {M : T} -> M.t; n : M.t >
@@ -87,7 +87,7 @@ type t_fail3 = < m : {M : T} -> M.t; n : M.t >
8787
Line 1, characters 41-44:
8888
1 | type t_fail3 = < m : {M : T} -> M.t; n : M.t >
8989
^^^
90-
Error: Unbound module "M"
90+
Error: Unbound module M
9191
|}]
9292

9393
(* should this fail ? *)
@@ -120,7 +120,7 @@ type t_fail6 = {M : T} -> 'a constraint 'a = M.t
120120
Line 1, characters 45-48:
121121
1 | type t_fail6 = {M : T} -> 'a constraint 'a = M.t
122122
^^^
123-
Error: Unbound module "M"
123+
Error: Unbound module M
124124
|}]
125125

126126
let id_fail1 (x : t1) : _ t5 = x
@@ -130,9 +130,9 @@ Line 1, characters 31-32:
130130
1 | let id_fail1 (x : t1) : _ t5 = x
131131
^
132132
Error: This expression has type
133-
"t1" = "{T : T} -> {A : Add with type t = T.t} -> A.t -> A.t"
133+
t1 = {T : T} -> {A : Add with type t = T.t} -> A.t -> A.t
134134
but an expression was expected of type
135-
"'a t5" = "{M : T with type t = 'a} -> 'a"
135+
'a t5 = {M : T with type t = 'a} -> 'a
136136
|}]
137137

138138
let id_fail2 (x : _ t5) : t1 = x
@@ -141,7 +141,7 @@ let id_fail2 (x : _ t5) : t1 = x
141141
Line 1, characters 31-32:
142142
1 | let id_fail2 (x : _ t5) : t1 = x
143143
^
144-
Error: This expression has type "'a t5" = "{M : T with type t = 'a} -> 'a"
144+
Error: This expression has type 'a t5 = {M : T with type t = 'a} -> 'a
145145
but an expression was expected of type
146-
"t1" = "{T : T} -> {A : Add with type t = T.t} -> A.t -> A.t"
146+
t1 = {T : T} -> {A : Add with type t = T.t} -> A.t -> A.t
147147
|}]

0 commit comments

Comments
 (0)