File tree 3 files changed +53
-7
lines changed
typing-layouts-non-null-value
3 files changed +53
-7
lines changed Original file line number Diff line number Diff line change @@ -127,3 +127,47 @@ let _ = my_id4 (Fake_or_null.some 4)
127
127
- : int Fake_or_null. t = < abstr>
128
128
- : int Fake_or_null. t = < abstr>
129
129
| }]
130
+
131
+ (* Check behavior of type arguments and unboxed annotations. *)
132
+
133
+ module M2 : sig
134
+ type 'a t = { v : 'a } [@@ unboxed]
135
+
136
+ val box : 'a -> 'a t
137
+ val unbox : 'a t -> 'a
138
+ end = struct
139
+ type 'a t = { v : 'a } [@@ unboxed]
140
+
141
+ let box v = { v }
142
+ let unbox { v } = v
143
+ end
144
+
145
+ [%% expect{|
146
+ module M2 :
147
+ sig
148
+ type 'a t = { v : 'a ; } [@@ unboxed]
149
+ val box : 'a -> 'a t
150
+ val unbox : 'a t -> 'a
151
+ end
152
+ | }]
153
+
154
+ module M3 : sig
155
+ type 'a t = V of 'a [@@ unboxed]
156
+
157
+ val box : 'a -> 'a t
158
+ val unbox : 'a t -> 'a
159
+ end = struct
160
+ type 'a t = V of 'a [@@ unboxed]
161
+
162
+ let box v = V v
163
+ let unbox (V v ) = v
164
+ end
165
+
166
+ [%% expect{|
167
+ module M3 :
168
+ sig
169
+ type 'a t = V of 'a [@@ unboxed]
170
+ val box : 'a -> 'a t
171
+ val unbox : 'a t -> 'a
172
+ end
173
+ | }]
Original file line number Diff line number Diff line change @@ -693,15 +693,15 @@ module M9_4 = struct
693
693
| ({vur_void = _ } ,i ) -> i
694
694
end ;;
695
695
[%% expect {|
696
- Line 4 , characters 8-16 :
696
+ Line 4 , characters 7-21 :
697
697
4 | | ({vur_void = _ } ,i ) -> i
698
- ^^^^^^^^
699
- Error : The record field vur_void belongs to the type void_unboxed_record
700
- but is mixed here with fields of type ('a : non_null_value )
698
+ ^^^^^^ ^^^^^^^^
699
+ Error : This pattern matches values of type void_unboxed_record
700
+ but a pattern was expected which matches values of type ('a : value )
701
701
The layout of void_unboxed_record is void, because
702
702
of the definition of t_void at line 6 , characters 0 -19.
703
- But the layout of void_unboxed_record must be a sublayout of non_null_value , because
704
- it's a boxed record type .
703
+ But the layout of void_unboxed_record must be a sublayout of value , because
704
+ it's the type of a tuple element .
705
705
| }];;
706
706
707
707
module M9_5 = struct
Original file line number Diff line number Diff line change @@ -2669,7 +2669,9 @@ and type_pat_aux
2669
2669
let ty = generic_instance expected_ty in
2670
2670
Some (p0, p, is_principal expected_ty), ty
2671
2671
| Maybe_a_record_type ->
2672
- None , newvar (Jkind. non_null_value ~why: Boxed_record )
2672
+ (* We can't assume that the jkind of a record type is [non_null_value]
2673
+ because of unboxed records. *)
2674
+ None , newvar (Jkind. any ~why: Dummy_jkind )
2673
2675
| Not_a_record_type ->
2674
2676
let error = Wrong_expected_kind (Record , Pattern , expected_ty) in
2675
2677
raise (Error (loc, ! env, error))
You can’t perform that action at this time.
0 commit comments