-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathbasics.ml
1479 lines (1248 loc) · 39 KB
/
basics.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(* TEST
* expect
flags = "-extension layouts"
* expect
flags = "-extension layouts_beta"
*)
type t_value : value
type t_imm : immediate
type t_imm64 : immediate64
type t_float64 : float64;;
type t_any : any;;
[%%expect{|
type t_value : value
type t_imm : immediate
type t_imm64 : immediate64
type t_float64 : float64
type t_any : any
|}]
type t_void : void;;
[%%expect{|
Line 1, characters 15-19:
1 | type t_void : void;;
^^^^
Error: Layout void is more experimental than allowed by the enabled layouts extension.
You must enable -extension layouts_alpha to use this feature.
|}];;
(******************************************************************)
(* Test 1: Allow non-representable function args/returns in types *)
module type S1 = sig
val f : int -> t_any
end;;
[%%expect {|
module type S1 = sig val f : int -> t_any end
|}];;
module type S1 = sig
val f : t_any -> int
end;;
[%%expect {|
module type S1 = sig val f : t_any -> int end
|}];;
module type S1 = sig
type t : any
type ('a : any) s = ('a : any) -> int constraint ('a : any) = t
end;;
[%%expect{|
module type S1 = sig type t : any type 'a s = 'a -> int constraint 'a = t end
|}]
module type S1 = sig
type t : any
type ('a : any) s = int -> ('a : any) constraint ('a : any) = t
end;;
[%%expect{|
module type S1 = sig type t : any type 'a s = int -> 'a constraint 'a = t end
|}]
module type S1 = sig
type t : any
type 'a s = 'a -> int constraint 'a = t
end;;
[%%expect{|
Line 4, characters 35-41:
4 | type 'a s = 'a -> int constraint 'a = t
^^^^^^
Error: The type constraints are not consistent.
Type ('a : '_representable_layout_1) is not compatible with type t
t has layout any, which is not representable.
|}]
module type S1 = sig
type t : any
type 'a s = int -> 'a constraint 'a = t
end;;
[%%expect{|
Line 4, characters 35-41:
4 | type 'a s = int -> 'a constraint 'a = t
^^^^^^
Error: The type constraints are not consistent.
Type ('a : '_representable_layout_2) is not compatible with type t
t has layout any, which is not representable.
|}]
let f1 () : t_any = assert false;;
[%%expect{|
Line 1, characters 20-32:
1 | let f1 () : t_any = assert false;;
^^^^^^^^^^^^
Error: This expression has type t_any but an expression was expected of type
('a : '_representable_layout_3)
t_any has layout any, which is not representable.
|}];;
let f1 (x : t_any) = ();;
[%%expect{|
Line 1, characters 7-18:
1 | let f1 (x : t_any) = ();;
^^^^^^^^^^^
Error: This pattern matches values of type t_any
but a pattern was expected which matches values of type
('a : '_representable_layout_4)
t_any has layout any, which is not representable.
|}];;
(*****************************************************)
(* Test 2: Permit representable function arg/returns *)
(* CR layouts v5: the void bits of this test should be copied here from
basics_alpha *)
module type S = sig
val f1 : t_value -> t_value
val f2 : t_imm -> t_imm64
end;;
[%%expect{|
module type S = sig val f1 : t_value -> t_value val f2 : t_imm -> t_imm64 end
|}];;
module type S2 = sig
val g : float# -> int
end;;
[%%expect{|
module type S2 = sig val g : float# -> int end
|}];;
module type S2 = sig
val g : int -> float#
end
[%%expect {|
module type S2 = sig val g : int -> float# end
|}];;
module type S2 = sig
type t' : float64
type s' = r' -> int
and r' = t'
end;;
[%%expect{|
module type S2 = sig type t' : float64 type s' = r' -> int and r' = t' end
|}]
module type S2 = sig
val f : int -> t_float64
end;;
[%%expect {|
module type S2 = sig val f : int -> t_float64 end
|}];;
module type S = sig
type t' : float64
type 'a s' = 'a -> int constraint 'a = t'
end;;
[%%expect{|
module type S =
sig type t' : float64 type 'a s' = 'a -> int constraint 'a = t' end
|}]
module F2 (X : sig val x : t_float64 end) = struct
let f () = X.x
end;;
[%%expect{|
Line 1, characters 27-36:
1 | module F2 (X : sig val x : t_float64 end) = struct
^^^^^^^^^
Error: This type signature for x is not a value type.
x has layout float64, which is not a sublayout of value.
|}];;
(* CR layouts v5: the test above should be made to work *)
module F2 (X : sig val f : t_float64 -> unit end) = struct
let g z = X.f z
end;;
[%%expect{|
module F2 :
functor (X : sig val f : t_float64 -> unit end) ->
sig val g : t_float64 -> unit end
|}];;
(**************************************)
(* Test 3: basic annotated parameters *)
type ('a : immediate) imm_id = 'a
[%%expect{|
type ('a : immediate) imm_id = 'a
|}];;
type my_int = int imm_id
let plus_3 (x : my_int) = x + 3
let plus_3' (x : int imm_id) = x + 3;;
[%%expect{|
type my_int = int imm_id
val plus_3 : my_int -> int = <fun>
val plus_3' : int imm_id -> int = <fun>
|}];;
let string_id (x : string imm_id) = x;;
[%%expect{|
Line 1, characters 19-25:
1 | let string_id (x : string imm_id) = x;;
^^^^^^
Error: This type string should be an instance of type ('a : immediate)
string has layout value, which is not a sublayout of immediate.
|}];;
let id_for_imms (x : 'a imm_id) = x
let three = id_for_imms 3
let true_ = id_for_imms true;;
[%%expect{|
val id_for_imms : ('a : immediate). 'a imm_id -> 'a imm_id = <fun>
val three : int imm_id = 3
val true_ : bool imm_id = true
|}]
let not_helloworld = id_for_imms "hello world";;
[%%expect{|
Line 1, characters 33-46:
1 | let not_helloworld = id_for_imms "hello world";;
^^^^^^^^^^^^^
Error: This expression has type string but an expression was expected of type
'a imm_id = ('a : immediate)
string has layout value, which is not a sublayout of immediate.
|}]
(************************************)
(* Test 4: parameters and recursion *)
type ('a : immediate) t4
and s4 = string t4;;
[%%expect{|
Line 2, characters 9-15:
2 | and s4 = string t4;;
^^^^^^
Error: This type string should be an instance of type ('a : immediate)
string has layout value, which is not a sublayout of immediate.
|}];;
type s4 = string t4
and ('a : immediate) t4;;
[%%expect{|
Line 1, characters 10-16:
1 | type s4 = string t4
^^^^^^
Error: This type string should be an instance of type ('a : immediate)
string has layout value, which is not a sublayout of immediate.
|}]
type s4 = int t4
and ('a : immediate) t4;;
[%%expect{|
type s4 = int t4
and ('a : immediate) t4
|}]
type s4 = s5 t4
and ('a : immediate) t4
and s5 = int;;
[%%expect{|
type s4 = s5 t4
and ('a : immediate) t4
and s5 = int
|}]
type s4 = s5 t4
and ('a : immediate) t4
and s5 = string;;
[%%expect{|
Line 3, characters 0-15:
3 | and s5 = string;;
^^^^^^^^^^^^^^^
Error:
s5 has layout value, which is not a sublayout of immediate.
|}]
(* CR layouts v2.9: improve error, which requires layout histories *)
type ('a : any) t4 = 'a
and s4 = string t4;;
[%%expect{|
type ('a : any) t4 = 'a
and s4 = string t4
|}];;
type s4 = string t4
and ('a : any) t4;;
[%%expect{|
type s4 = string t4
and ('a : any) t4
|}];;
type ('a : void) void4 = Void4 of 'a;;
[%%expect{|
Line 1, characters 11-15:
1 | type ('a : void) void4 = Void4 of 'a;;
^^^^
Error: Layout void is more experimental than allowed by the enabled layouts extension.
You must enable -extension layouts_alpha to use this feature.
|}];;
type ('a : any) any4 = Any4 of 'a
[%%expect{|
type 'a any4 = Any4 of 'a
|}];;
(************************************************************)
(* Test 5: You can touch a void, but not return it directly *)
(* CR layouts v5: these tests moved to [basics_alpha.ml]. Bring them here.
Also the tests will change because we'll allow returning void. *)
(****************************************)
(* Test 6: explicitly polymorphic types *)
type ('a : immediate) t6_imm = T6imm of 'a
type ('a : value) t6_val = T6val of 'a;;
[%%expect{|
type ('a : immediate) t6_imm = T6imm of 'a
type 'a t6_val = T6val of 'a
|}];;
let ignore_val6 : 'a . 'a -> unit =
fun a -> let _ = T6val a in ();;
[%%expect{|
val ignore_val6 : 'a -> unit = <fun>
|}];;
let ignore_imm6 : 'a . 'a -> unit =
fun a -> let _ = T6imm a in ();;
[%%expect{|
Line 2, characters 2-32:
2 | fun a -> let _ = T6imm a in ();;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: This definition has type 'b -> unit which is less general than
'a. 'a -> unit
'a has layout value, which is not a sublayout of immediate.
|}];;
let o6 = object
method ignore_imm6 : 'a . 'a -> unit =
fun a -> let _ = T6imm a in ()
end;;
[%%expect{|
Line 3, characters 4-34:
3 | fun a -> let _ = T6imm a in ()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: This method has type 'b -> unit which is less general than
'a. 'a -> unit
'a has layout value, which is not a sublayout of immediate.
|}];;
(* CR layouts v1.5: add more tests here once you can annotate these types with
jkinds. *)
(****************************************)
(* Test 7: the jkind check in unify_var *)
type ('a : immediate) t7 = Foo7 of 'a
type t7' = (int * int) t7;;
[%%expect{|
type ('a : immediate) t7 = Foo7 of 'a
Line 3, characters 12-21:
3 | type t7' = (int * int) t7;;
^^^^^^^^^
Error: This type int * int should be an instance of type ('a : immediate)
int * int has layout value, which is not a sublayout of immediate.
|}]
(**********************************************************)
(* Test 8: Polymorphic variants take value args (for now) *)
(* CR layouts v5: Bring over void versions of these tests. *)
module M8_1f = struct
type foo1 = [ `Foo1 of int | `Baz1 of t_float64 | `Bar1 of string ];;
end
[%%expect{|
Line 2, characters 40-49:
2 | type foo1 = [ `Foo1 of int | `Baz1 of t_float64 | `Bar1 of string ];;
^^^^^^^^^
Error: Polymorphic variant constructor argument types must have layout value.
t_float64 has layout float64, which is not a sublayout of value.
|}];;
module M8_2f = struct
let foo x =
match x with
| `Baz 42 -> Stdlib__Float_u.of_float 3.14
| `Bar v -> v
| `Bas i -> Stdlib__Float_u.of_float 3.14
end;;
[%%expect {|
Line 5, characters 16-17:
5 | | `Bar v -> v
^
Error: This expression has type ('a : value)
but an expression was expected of type float#
float# has layout float64, which is not a sublayout of value.
|}];;
module M8_3f = struct
type 'a t = [ `Foo of 'a | `Baz of int ]
type bad = t_float64 t
end;;
[%%expect {|
Line 4, characters 13-22:
4 | type bad = t_float64 t
^^^^^^^^^
Error: This type t_float64 should be an instance of type ('a : value)
t_float64 has layout float64, which is not a sublayout of value.
|}];;
module M8_4f = struct
type 'a t = [ `Foo of 'a | `Baz of int ] constraint 'a = t_float64
end;;
[%%expect {|
Line 2, characters 54-68:
2 | type 'a t = [ `Foo of 'a | `Baz of int ] constraint 'a = t_float64
^^^^^^^^^^^^^^
Error: The type constraints are not consistent.
Type ('a : value) is not compatible with type t_float64
t_float64 has layout float64, which is not a sublayout of value.
|}];;
module type S8_5f = sig
val x : [`A of t_float64]
end;;
[%%expect{|
Line 2, characters 17-26:
2 | val x : [`A of t_float64]
^^^^^^^^^
Error: Polymorphic variant constructor argument types must have layout value.
t_float64 has layout float64, which is not a sublayout of value.
|}]
(************************************************)
(* Test 9: Tuples only work on values (for now) *)
(* CR layouts v5: bring over void tests. *)
module M9_1f = struct
type foo1 = int * t_float64 * [ `Foo1 of int | `Bar1 of string ];;
end
[%%expect{|
Line 2, characters 20-29:
2 | type foo1 = int * t_float64 * [ `Foo1 of int | `Bar1 of string ];;
^^^^^^^^^
Error: Tuple element types must have layout value.
t_float64 has layout float64, which is not a sublayout of value.
|}];;
module M9_2f = struct
type result = V of (string * t_float64) | I of int
end;;
[%%expect {|
Line 2, characters 31-40:
2 | type result = V of (string * t_float64) | I of int
^^^^^^^^^
Error: Tuple element types must have layout value.
t_float64 has layout float64, which is not a sublayout of value.
|}];;
module M9_4f = struct
let f_id (x : float#) = x
let foo x =
match x with
| (a, _) -> f_id a
end;;
[%%expect {|
Line 6, characters 21-22:
6 | | (a, _) -> f_id a
^
Error: This expression has type ('a : value)
but an expression was expected of type float#
float# has layout float64, which is not a sublayout of value.
|}];;
module M9_5f = struct
type 'a t = (int * 'a)
type bad = t_float64 t
end;;
[%%expect {|
Line 4, characters 13-22:
4 | type bad = t_float64 t
^^^^^^^^^
Error: This type t_float64 should be an instance of type ('a : value)
t_float64 has layout float64, which is not a sublayout of value.
|}];;
module M9_6f = struct
type 'a t = int * 'a constraint 'a = t_float64
end;;
[%%expect {|
Line 2, characters 34-48:
2 | type 'a t = int * 'a constraint 'a = t_float64
^^^^^^^^^^^^^^
Error: The type constraints are not consistent.
Type ('a : value) is not compatible with type t_float64
t_float64 has layout float64, which is not a sublayout of value.
|}];;
module type S9_7f = sig
val x : int * t_float64
end;;
[%%expect{|
Line 2, characters 16-25:
2 | val x : int * t_float64
^^^^^^^^^
Error: Tuple element types must have layout value.
t_float64 has layout float64, which is not a sublayout of value.
|}];;
(*************************************************)
(* Test 10: jkinds are checked by "more general" *)
(* This hits the first linktype in moregen (no expansion required to see it's a
var) *)
module M10_1 : sig
val x : string
end = struct
type ('a : immediate) t = 'a
let f : 'a t -> 'a = fun x -> x
let x = f (assert false)
end;;
[%%expect {|
Lines 3-9, characters 6-3:
3 | ......struct
4 | type ('a : immediate) t = 'a
5 |
6 | let f : 'a t -> 'a = fun x -> x
7 |
8 | let x = f (assert false)
9 | end..
Error: Signature mismatch:
Modules do not match:
sig
type ('a : immediate) t = 'a
val f : ('a : immediate). 'a t -> 'a
val x : ('a : immediate). 'a
end
is not included in
sig val x : string end
Values do not match:
val x : ('a : immediate). 'a
is not included in
val x : string
The type ('a : immediate) is not compatible with the type string
string has layout value, which is not a sublayout of immediate.
|}];;
(* This hits the second linktype in moregen (requires expansion to see it's a
var) *)
module M10_2 : sig
val x : string
end = struct
type ('a : immediate) t = 'a
let f (x : 'a t) : 'a t = x
let x = f (assert false)
end;;
[%%expect {|
Lines 3-9, characters 6-3:
3 | ......struct
4 | type ('a : immediate) t = 'a
5 |
6 | let f (x : 'a t) : 'a t = x
7 |
8 | let x = f (assert false)
9 | end..
Error: Signature mismatch:
Modules do not match:
sig
type ('a : immediate) t = 'a
val f : ('a : immediate). 'a t -> 'a t
val x : ('a : immediate). 'a t
end
is not included in
sig val x : string end
Values do not match:
val x : ('a : immediate). 'a t
is not included in
val x : string
The type 'a t = ('a : immediate) is not compatible with the type
string
string has layout value, which is not a sublayout of immediate.
|}]
(**********************************************************************)
(* Test 11: objects are values. methods may take/return other sorts. *)
(* CR layouts v5: bring the void versions back here. *)
module M11_1 = struct
type ('a : void) t = { x : int; v : 'a }
let f t =
t.v # baz11
end;;
[%%expect{|
Line 2, characters 13-17:
2 | type ('a : void) t = { x : int; v : 'a }
^^^^
Error: Layout void is more experimental than allowed by the enabled layouts extension.
You must enable -extension layouts_alpha to use this feature.
|}]
module M11_1f = struct
type ('a : float64) t = 'a
let f (x : 'a t) =
x # baz11
end;;
[%%expect{|
Line 5, characters 4-5:
5 | x # baz11
^
Error: Method types must have layout value.
This expression has layout float64, which does not overlap with value.
|}]
module M11_2f = struct
type ('a : float64) t = 'a
let f_id (x : 'a t) = x
let foo x = f_id (x # getfloat)
end;;
[%%expect{|
Line 4, characters 19-33:
4 | let foo x = f_id (x # getfloat)
^^^^^^^^^^^^^^
Error: This expression has type ('a : value)
but an expression was expected of type 'b t = ('b : float64)
'a t has layout float64, which does not overlap with value.
|}];;
module M11_3f = struct
type ('a : float64) t = 'a
let foo o (x : 'a t) = o # usefloat x
end;;
[%%expect{|
module M11_3f :
sig
type ('a : float64) t = 'a
val foo : 'b ('a : float64). < usefloat : 'a t -> 'b; .. > -> 'a t -> 'b
end
|}];;
module M11_4f = struct
val x : < l : t_float64 >
end;;
[%%expect{|
Line 2, characters 12-25:
2 | val x : < l : t_float64 >
^^^^^^^^^^^^^
Error: Object field types must have layout value.
t_float64 has layout float64, which is not a sublayout of value.
|}];;
module M11_5f = struct
type 'a t = < l : 'a s >
and ('a : float64) s = 'a
end;;
[%%expect{|
Line 3, characters 2-27:
3 | and ('a : float64) s = 'a
^^^^^^^^^^^^^^^^^^^^^^^^^
Error:
'a s has layout float64, which does not overlap with value.
|}];;
module M11_6f = struct
type 'a t = < l : 'a > constraint 'a = t_float64
end;;
[%%expect{|
Line 2, characters 36-50:
2 | type 'a t = < l : 'a > constraint 'a = t_float64
^^^^^^^^^^^^^^
Error: The type constraints are not consistent.
Type ('a : value) is not compatible with type t_float64
t_float64 has layout float64, which is not a sublayout of value.
|}];;
(*******************************************************************)
(* Test 12: class parameters and bound vars must have jkind value *)
(* CR layouts v5: Bring the void versions back here. *)
(* Hits `Pcl_let` *)
module M12_1f = struct
let f : ('a : float64) . unit -> 'a = fun () -> assert false
class foo12 u =
let d = f u in
object
val bar = ()
end;;
end
[%%expect{|
Line 4, characters 8-9:
4 | let d = f u in
^
Error: The types of variables bound by a 'let' in a class function
must have layout value. Instead, d's type has layout float64.
|}];;
(* Hits the Cfk_concrete case of Pcf_val *)
module M12_2f = struct
let f : ('a : float64) . unit -> 'a = fun () -> assert false
class foo u =
object
val bar = f u
end
end;;
[%%expect{|
Line 5, characters 10-13:
5 | val bar = f u
^^^
Error: Variables bound in a class must have layout value.
bar has layout float64, which does not overlap with value.
|}];;
(* Hits the Cfk_virtual case of Pcf_val *)
module M12_3f = struct
class virtual foo =
object
val virtual bar : t_float64
end
end;;
[%%expect{|
Line 4, characters 18-21:
4 | val virtual bar : t_float64
^^^
Error: Variables bound in a class must have layout value.
bar has layout float64, which is not a sublayout of value.
|}];;
module M12_4f = struct
type ('a : float64) t
class virtual ['a] foo =
object
val virtual baz : 'a t
end
end
[%%expect{|
Line 6, characters 24-26:
6 | val virtual baz : 'a t
^^
Error: This type ('a : float64) should be an instance of type ('a0 : value)
'a has layout value, which does not overlap with float64.
|}];;
module M12_5f = struct
type ('a : float64) t = 'a
class ['a] foo =
object
method void_id (a : 'a t) : 'a t = a
end
end;;
[%%expect{|
Line 6, characters 26-28:
6 | method void_id (a : 'a t) : 'a t = a
^^
Error: This type ('a : float64) should be an instance of type ('a0 : value)
'a has layout value, which does not overlap with float64.
|}];;
module type S12_6f = sig
type ('a : float64) t = 'a
class ['a] foo :
'a t ->
object
method baz : int
end
end;;
[%%expect{|
Line 5, characters 4-6:
5 | 'a t ->
^^
Error: This type ('a : float64) should be an instance of type ('a0 : value)
'a has layout value, which does not overlap with float64.
|}];;
module type S12_7f = sig
class foo :
object
val baz : t_float64
end
end;;
[%%expect{|
Line 4, characters 6-25:
4 | val baz : t_float64
^^^^^^^^^^^^^^^^^^^
Error: Variables bound in a class must have layout value.
baz has layout float64, which is not a sublayout of value.
|}];;
(***********************************************************)
(* Test 13: built-in type constructors work only on values *)
(* CR layouts v5: Bring the void versions over from basics_alpha *)
(* lazy *)
type t13f = t_float64 Lazy.t;;
[%%expect{|
Line 1, characters 12-21:
1 | type t13f = t_float64 Lazy.t;;
^^^^^^^^^
Error: This type t_float64 should be an instance of type ('a : value)
t_float64 has layout float64, which is not a sublayout of value.
|}];;
let x13f (v : t_float64) = lazy v;;
[%%expect{|
Line 1, characters 32-33:
1 | let x13f (v : t_float64) = lazy v;;
^
Error: This expression has type t_float64
but an expression was expected of type ('a : value)
t_float64 has layout float64, which is not a sublayout of value.
|}];;
let f_id (x : t_float64) = x
let x13f v =
match v with
| lazy v -> f_id v
[%%expect{|
val f_id : t_float64 -> t_float64 = <fun>
Line 4, characters 19-20:
4 | | lazy v -> f_id v
^
Error: This expression has type ('a : value)
but an expression was expected of type t_float64
t_float64 has layout float64, which is not a sublayout of value.
|}];;
(* option *)
(* CR layouts v5: allow this *)
type t13f = t_float64 option;;
[%%expect{|
Line 1, characters 12-21:
1 | type t13f = t_float64 option;;
^^^^^^^^^
Error: This type t_float64 should be an instance of type ('a : value)
t_float64 has layout float64, which is not a sublayout of value.
|}];;
let x13f (v : t_float64) = Some v;;
[%%expect{|
Line 1, characters 32-33:
1 | let x13f (v : t_float64) = Some v;;
^
Error: This expression has type t_float64
but an expression was expected of type ('a : value)
t_float64 has layout float64, which is not a sublayout of value.
|}];;
let x13f v =
match v with
| Some v -> f_id v
| None -> assert false
[%%expect{|
Line 3, characters 19-20:
3 | | Some v -> f_id v
^
Error: This expression has type ('a : value)
but an expression was expected of type t_float64
t_float64 has layout float64, which is not a sublayout of value.
|}];;
(* list *)
type t13f = t_float64 list;;
[%%expect{|
Line 1, characters 12-21:
1 | type t13f = t_float64 list;;
^^^^^^^^^
Error: This type t_float64 should be an instance of type ('a : value)
t_float64 has layout float64, which is not a sublayout of value.
|}];;
let x13 (v : t_float64) = [v];;
[%%expect{|
Line 1, characters 27-28:
1 | let x13 (v : t_float64) = [v];;
^
Error: This expression has type t_float64
but an expression was expected of type ('a : value)
t_float64 has layout float64, which is not a sublayout of value.
|}];;
let x13 v =
match v with
| [v] -> f_id v
| _ -> assert false
[%%expect{|
Line 3, characters 16-17:
3 | | [v] -> f_id v
^
Error: This expression has type ('a : value)
but an expression was expected of type t_float64
t_float64 has layout float64, which is not a sublayout of value.
|}];;
(* array *)
type t13f = t_float64 array;;
[%%expect{|
Line 1, characters 12-21:
1 | type t13f = t_float64 array;;
^^^^^^^^^
Error: This type t_float64 should be an instance of type ('a : value)
t_float64 has layout float64, which is not a sublayout of value.
|}];;
let x13f (v : t_float64) = [| v |];;
[%%expect{|
Line 1, characters 30-31:
1 | let x13f (v : t_float64) = [| v |];;
^
Error: This expression has type t_float64
but an expression was expected of type ('a : value)
t_float64 has layout float64, which is not a sublayout of value.
|}];;
let x13f v =
match v with
| [| v |] -> f_id v
| _ -> assert false
[%%expect{|
Line 3, characters 20-21:
3 | | [| v |] -> f_id v
^
Error: This expression has type ('a : value)
but an expression was expected of type t_float64
t_float64 has layout float64, which is not a sublayout of value.
|}];;
(****************************************************************************)
(* Test 14: Examples motivating the trick with the manifest in [enter_type] *)
type t14 = foo14 list
and foo14 = string;;
[%%expect{|
type t14 = foo14 list
and foo14 = string
|}];;
(* CR layouts v5: Bring back void version from basics_alpha. *)
type t14 = foo14 list
and foo14 = t_float64;;
[%%expect{|
Line 2, characters 0-21:
2 | and foo14 = t_float64;;
^^^^^^^^^^^^^^^^^^^^^
Error:
foo14 has layout float64, which is not a sublayout of value.
|}];;
(****************************************************)
(* Test 15: Type aliases need not have jkind value *)
(* CR layouts v5: Bring back void version from basics_alpha. *)
type ('a : float64) t15
type ('a, 'b) foo15 = ('a as 'b) t15 -> 'b t15;;
[%%expect{|
type ('a : float64) t15
type ('a : float64, 'b) foo15 = 'a t15 -> 'a t15 constraint 'b = 'a
|}]
(********************************************************)
(* Test 16: seperability: [msig_of_external_type] logic *)
(* CR layouts v5: This test moved to [basics_alpha.ml] as it needs a non-value
sort in a variant. Bring back here when we have one. *)
type 'a t_void_16 : void;;
[%%expect{|
Line 1, characters 20-24:
1 | type 'a t_void_16 : void;;