@@ -24,119 +24,170 @@ type void_record = { vr_void : t_void; vr_int : int; }
24
24
type void_unboxed_record = { vur_void : t_void ; } [@@ unboxed]
25
25
|}];;
26
26
27
- (* ************************************************)
28
- (* Test 1: Reject non-value function arg/returns *)
29
-
30
- (* CR layouts v2: the F1 and F1' errors should ideally mention that the layout
31
- restriction is coming from the function type. This may be easier when we
32
- switch to introducing restrictions on [fun] *)
33
- module F1 (X : sig val x : t_void end ) = struct
34
- let f () = X. x
35
- end ;;
36
- [%% expect{|
37
- Line 2 , characters 13-16 :
38
- 2 | let f () = X. x
39
- ^^^
40
- Error : This expression has type t_void but an expression was expected of type
41
- ('a : value )
42
- t_void has layout void, which is not a sublayout of value.
43
- | }];;
44
-
45
- module F1 (X : sig val f : void_record -> unit end ) = struct
46
- let g z = X. f { vr_void = z; vr_int = 42 }
27
+ (* ***********************************************************)
28
+ (* Test 1: Disallow non-representable function args/returns *)
29
+ module type S1 = sig
30
+ val f : int -> t_any
47
31
end ;;
48
- [%% expect{|
49
- Line 2 , characters 28-29 :
50
- 2 | let g z = X. f { vr_void = z; vr_int = 42 }
51
- ^
52
- Error : This expression has type ('a : value )
53
- but an expression was expected of type t_void
54
- t_void has layout void, which is not a sublayout of value.
32
+ [%% expect {|
33
+ Line 2 , characters 17-22 :
34
+ 2 | val f : int -> t_any
35
+ ^^^^^
36
+ Error : Function return types must have a representable layout.
37
+ t_any has layout any, which is not representable.
55
38
| }];;
56
39
57
- module type S = sig
40
+ module type S1 = sig
58
41
val f : t_any -> int
59
42
end ;;
60
43
[%% expect {|
61
44
Line 2 , characters 10-15 :
62
45
2 | val f : t_any -> int
63
46
^^^^^
64
- Error : Function argument types must have layout value.
65
- t_any has layout any, which is not a sublayout of value.
47
+ Error : Function argument types must have a representable layout.
48
+ t_any has layout any, which is not representable.
49
+ | }];;
50
+
51
+ module type S1 = sig
52
+ type t [@@any]
53
+
54
+ type 'a s = 'a -> int constraint 'a = t
55
+ end ;;
56
+ [%% expect{|
57
+ Line 4 , characters 35-41 :
58
+ 4 | type 'a s = 'a -> int constraint 'a = t
59
+ ^^^^^^
60
+ Error : The type constraints are not consistent.
61
+ Type ('a : '_representable_layout_1 ) is not compatible with type t
62
+ t has layout any, which is not representable.
66
63
| }]
67
64
68
- module type S = sig
69
- val f : int -> t_void
65
+ module type S1 = sig
66
+ type t [@@any]
67
+
68
+ type 'a s = int -> 'a constraint 'a = t
70
69
end ;;
71
- [%% expect {|
72
- Line 2 , characters 17-23 :
73
- 2 | val f : int -> t_void
74
- ^^^^^^
75
- Error : Function return types must have layout value.
76
- t_void has layout void, which is not a sublayout of value.
70
+ [%% expect{|
71
+ Line 4 , characters 35-41 :
72
+ 4 | type 'a s = int -> 'a constraint 'a = t
73
+ ^^^^^^
74
+ Error : The type constraints are not consistent.
75
+ Type ('a : '_representable_layout_2 ) is not compatible with type t
76
+ t has layout any, which is not representable.
77
+ | }]
78
+
79
+ let f1 () : t_any = assert false ;;
80
+ [%% expect{|
81
+ Line 1 , characters 10-32 :
82
+ 1 | let f1 () : t_any = assert false ;;
83
+ ^^^^^^^^^^^^^^^^^^^^^^
84
+ Error : This expression has type t_any but an expression was expected of type
85
+ ('a : '_representable_layout_3 )
86
+ t_any has layout any, which is not representable.
77
87
| }];;
78
88
89
+ let f1 (x : t_any ) = () ;;
90
+ [%% expect{|
91
+ Line 1 , characters 7-18 :
92
+ 1 | let f1 (x : t_any ) = () ;;
93
+ ^^^^^^^^^^^
94
+ Error : This pattern matches values of type t_any
95
+ but a pattern was expected which matches values of type
96
+ ('a : '_representable_layout_4 )
97
+ t_any has layout any, which is not representable.
98
+ | }];;
99
+
100
+ (* ****************************************************)
101
+ (* Test 2: Permit representable function arg/returns *)
102
+
103
+ (* Presently, the typechecker will allow any representable layout as a function
104
+ arg or return type. The translation to lambda rejects functions with
105
+ void args / returns. *)
106
+ (* CR layouts v2: The translation to lambda should reject void but not #float *)
107
+ (* CR layouts v2: Once we have another sort that can make it through lambda
108
+ (#float), add tests showing the way sort variables will be instantiated.
109
+
110
+ 1) [let f x = x] roughly has type [('a : '_sort) -> ('a : '_sort)].
111
+ Test that you can apply it to a value or to a #float, but once you've
112
+ done that you can't apply it to the other.
113
+
114
+ 2) If [f] has a type in the mli (and isn't used in the ml) we get the sort
115
+ from there.
116
+
117
+ I think that all already works, but for the lack of #float *)
118
+
79
119
module type S = sig
120
+ val f1 : t_value -> t_value
121
+ val f2 : t_imm -> t_imm64
122
+ end ;;
123
+
124
+ [%% expect{|
125
+ module type S = sig val f1 : t_value -> t_value val f2 : t_imm -> t_imm64 end
126
+ | }];;
127
+
128
+ module type S2 = sig
80
129
val f : void_unboxed_record -> int
81
130
end
82
131
[%% expect {|
83
- Line 2 , characters 10-29 :
84
- 2 | val f : void_unboxed_record -> int
85
- ^^^^^^^^^^^^^^^^^^^
86
- Error : Function argument types must have layout value.
87
- void_unboxed_record has layout void,
88
- which is not a sublayout of value.
132
+ module type S2 = sig val f : void_unboxed_record -> int end
89
133
| }];;
90
134
91
- module type S = sig
135
+ module type S2 = sig
92
136
val f : int -> void_unboxed_record
93
137
end
94
138
[%% expect {|
95
- Line 2 , characters 17-36 :
96
- 2 | val f : int -> void_unboxed_record
97
- ^^^^^^^^^^^^^^^^^^^
98
- Error : Function return types must have layout value.
99
- void_unboxed_record has layout void,
100
- which is not a sublayout of value.
139
+ module type S2 = sig val f : int -> void_unboxed_record end
101
140
| }];;
102
141
103
- module type S = sig
142
+ module type S2 = sig
104
143
type t [@@void]
105
144
106
145
type s = r -> int
107
146
and r = t
108
147
end ;;
109
148
[%% expect{|
110
- Line 5 , characters 2-11 :
111
- 5 | and r = t
112
- ^^^^^^^^^
113
- Error :
114
- r has layout void, which is not a sublayout of value.
149
+ module type S2 = sig type t [@@ void] type s = r -> int and r = t end
115
150
| }]
116
151
152
+ module type S2 = sig
153
+ val f : int -> t_void
154
+ end ;;
155
+ [%% expect {|
156
+ module type S2 = sig val f : int -> t_void end
157
+ | }];;
158
+
117
159
module type S = sig
118
160
type t [@@void]
119
161
120
162
type 'a s = 'a -> int constraint 'a = t
121
163
end ;;
122
164
[%% expect{|
123
- Line 4 , characters 35-41 :
124
- 4 | type 'a s = 'a -> int constraint 'a = t
125
- ^^^^^^
126
- Error : The type constraints are not consistent.
127
- Type ('a : value ) is not compatible with type t
128
- t has layout void, which is not a sublayout of value.
165
+ module type S =
166
+ sig type t [@@ void] type 'a s = 'a -> int constraint 'a = t end
129
167
| }]
130
168
131
- (* ********************************************)
132
- (* Test 2: Permit value function arg/returns *)
133
- module type S = sig
134
- val f1 : t_value -> t_value
135
- val f2 : t_imm -> t_imm64
169
+ module F2 (X : sig val x : t_void end ) = struct
170
+ let f () = X. x
136
171
end ;;
172
+ [%% expect{|
173
+ Line 2 , characters 8-16 :
174
+ 2 | let f () = X. x
175
+ ^^^^^^^^
176
+ Error : Non - value detected in [value_kind].
177
+ Please report this error to the Jane Street compilers team.
178
+ t_void has layout void, which is not a sublayout of value.
179
+ | }];;
137
180
181
+ module F2 (X : sig val f : void_record -> unit end ) = struct
182
+ let g z = X. f { vr_void = z; vr_int = 42 }
183
+ end ;;
138
184
[%% expect{|
139
- module type S = sig val f1 : t_value -> t_value val f2 : t_imm -> t_imm64 end
185
+ Line 2 , characters 8-44 :
186
+ 2 | let g z = X. f { vr_void = z; vr_int = 42 }
187
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
188
+ Error : Non - value detected in [value_kind].
189
+ Please report this error to the Jane Street compilers team.
190
+ t_void has layout void, which is not a sublayout of value.
140
191
| }];;
141
192
142
193
(* *************************************)
@@ -318,19 +369,13 @@ let g (x : 'a void5) =
318
369
match x with
319
370
| Void5 x -> x;;
320
371
[%% expect{|
321
- Line 3 , characters 15-16 :
322
- 3 | | Void5 x -> x;;
323
- ^
324
- Error : This expression has type ('a : void )
325
- but an expression was expected of type ('b : value )
326
- 'a has layout value, which does not overlap with void.
327
- | }, Principal {|
328
- Lines 2-3 , characters 2-16 :
329
- 2 | ..match x with
372
+ Lines 1-3 , characters 6-16 :
373
+ 1 | ......(x : 'a void5 ) =
374
+ 2 | match x with
330
375
3 | | Void5 x -> x..
331
- Error : This expression has type ('a : void )
332
- but an expression was expected of type ('b : value )
333
- 'a has layout value , which does not overlap with void .
376
+ Error : Non - value detected in [value_kind].
377
+ Please report this error to the Jane Street compilers team.
378
+ 'a has layout void , which is not a sublayout of value .
334
379
| }]
335
380
336
381
(* ***************************************)
0 commit comments