File tree 7 files changed +60
-21
lines changed
7 files changed +60
-21
lines changed Original file line number Diff line number Diff line change @@ -783,7 +783,9 @@ let rec is_a_literal_case ~(literal_cases : Lambda.literal list) ~block_cases (e
783
783
(* We don't know the type of unknown, so we need to express:
784
784
this is not one of the literals *)
785
785
(match literal_cases with
786
- | [] -> { expression_desc = Bool true ; comment= None }
786
+ | [] ->
787
+ (* this should not happen *)
788
+ assert false
787
789
| l1 :: others ->
788
790
let is_literal_1 = is_literal_case l1 in
789
791
Ext_list. fold_right others is_literal_1 (fun literal_n acc ->
@@ -797,7 +799,7 @@ let rec is_a_literal_case ~(literal_cases : Lambda.literal list) ~block_cases (e
797
799
bin And (is_block_case c1) (is_a_literal_case ~literal_cases ~block_cases: rest e)
798
800
| [] -> assert false
799
801
800
- let is_tag ?(has_null_undefined_other =(false , false , false )) (e : t ) : t =
802
+ let is_int_tag ?(has_null_undefined_other =(false , false , false )) (e : t ) : t =
801
803
let (has_null, has_undefined, has_other) = has_null_undefined_other in
802
804
if has_null && (has_undefined = false ) && (has_other = false ) then (* null *)
803
805
{ expression_desc = Bin (EqEqEq , e, nil); comment= None }
Original file line number Diff line number Diff line change @@ -202,7 +202,7 @@ val neq_null_undefined_boolean : ?comment:string -> t -> t -> t
202
202
203
203
val is_type_number : ?comment : string -> t -> t
204
204
205
- val is_tag : ?has_null_undefined_other : (bool * bool * bool ) -> t -> t
205
+ val is_int_tag : ?has_null_undefined_other : (bool * bool * bool ) -> t -> t
206
206
207
207
val is_a_literal_case : literal_cases :Lambda .literal list -> block_cases :Lambda .block_type list -> t -> t
208
208
Original file line number Diff line number Diff line change @@ -172,7 +172,7 @@ let get_literal_cases (sw_names : Lambda.switch_names option) =
172
172
| Some { consts } ->
173
173
Ext_array. iter consts (function
174
174
| {literal = Some literal } -> res := literal :: ! res
175
- | {literal = None } -> ()
175
+ | {name; literal = None } -> res := String name :: ! res
176
176
)
177
177
);
178
178
! res
@@ -691,14 +691,14 @@ and compile_switch (switch_arg : Lam.t) (sw : Lam.lambda_switch)
691
691
else
692
692
(* [e] will be used twice *)
693
693
let dispatch e =
694
- let is_tag =
694
+ let is_a_literal_case =
695
695
if block_cases <> []
696
- then E. is_a_literal_case ~literal_cases: (get_literal_cases sw_names) ~block_cases e
696
+ then
697
+ E. is_a_literal_case ~literal_cases: (get_literal_cases sw_names) ~block_cases e
697
698
else
698
- E. is_tag ~has_null_undefined_other: (has_null_undefined_other sw_names) e in
699
- S. if_ is_tag
699
+ E. is_int_tag ~has_null_undefined_other: (has_null_undefined_other sw_names) e in
700
+ S. if_ is_a_literal_case
700
701
(compile_cases cxt e sw_consts sw_num_default get_const_name)
701
- (* default still needed, could simplified*)
702
702
~else_:
703
703
(compile_cases ~untagged cxt (if untagged then e else E. tag ~name: tag_name e) sw_blocks sw_blocks_default
704
704
get_block_name)
Original file line number Diff line number Diff line change @@ -1329,11 +1329,10 @@ let make_constr_matching p def ctx = function
1329
1329
[] -> fatal_error " Matching.make_constr_matching"
1330
1330
| ((arg , _mut ) :: argl ) ->
1331
1331
let cstr = pat_as_constr p in
1332
+ let untagged =
1333
+ Ext_list. exists cstr.cstr_attributes (function ({txt} , _ ) -> txt = " unboxed" ) in
1332
1334
let newargs =
1333
- if cstr.cstr_inlined <> None ||
1334
- Ext_list. exists cstr.cstr_attributes (function
1335
- | ({txt ="unboxed" } , _ ) -> true
1336
- | _ -> false ) then
1335
+ if cstr.cstr_inlined <> None || (untagged && cstr.cstr_args <> [] ) then
1337
1336
(arg, Alias ) :: argl
1338
1337
else match cstr.cstr_tag with
1339
1338
| Cstr_block _ when
Original file line number Diff line number Diff line change @@ -92,11 +92,15 @@ var TwoObjects = {
92
92
} ;
93
93
94
94
function classify$2 ( x ) {
95
- if ( x === "A" ) {
96
- return "a" ;
97
- } else {
98
- return "b" ;
95
+ if ( x === "A" || x === "B" ) {
96
+ if ( x === "A" ) {
97
+ return "a" ;
98
+ } else {
99
+ return "b" ;
100
+ }
99
101
}
102
+ console . log ( x ) ;
103
+ return "Unknown" ;
100
104
}
101
105
102
106
var Unknown = {
@@ -211,6 +215,26 @@ var Json = {
211
215
classify : classify$6
212
216
} ;
213
217
218
+ function check ( s , y ) {
219
+ if ( s === "B" ) {
220
+ return 42 ;
221
+ }
222
+ var x = s [ 0 ] ;
223
+ if ( x === "B" ) {
224
+ return 42 ;
225
+ }
226
+ var tmp = s [ 1 ] ;
227
+ if ( tmp === "B" && x !== y ) {
228
+ return 41 ;
229
+ } else {
230
+ return 42 ;
231
+ }
232
+ }
233
+
234
+ var TrickyNested = {
235
+ check : check
236
+ } ;
237
+
214
238
var i = 42 ;
215
239
216
240
var i2 = 42.5 ;
@@ -244,4 +268,5 @@ exports.MultipleBlocks = MultipleBlocks;
244
268
exports . OnlyBlocks = OnlyBlocks ;
245
269
exports . WithArray = WithArray ;
246
270
exports . Json = Json ;
271
+ exports . TrickyNested = TrickyNested ;
247
272
/* l2 Not a pure module */
Original file line number Diff line number Diff line change @@ -183,3 +183,16 @@ let classify (x : t) : tagged_t =
183
183
JSONObject (Obj.magic x)
184
184
*/
185
185
}
186
+
187
+ module TrickyNested = {
188
+ @unboxed
189
+ type rec t =
190
+ | A ((t , t ))
191
+ | B
192
+
193
+ let check = (s , y ) =>
194
+ switch s {
195
+ | A ((A (x ), B )) if x !== y => 41
196
+ | _ => 42
197
+ }
198
+ }
Original file line number Diff line number Diff line change @@ -278,7 +278,7 @@ function isWhyNot(x) {
278
278
}
279
279
280
280
function plus$3 ( x , y ) {
281
- if ( x === null || x === undefined ) {
281
+ if ( x === undefined || x === null || x === "WhyNotAnotherOne" ) {
282
282
switch ( x ) {
283
283
case null :
284
284
case undefined :
@@ -287,13 +287,13 @@ function plus$3(x, y) {
287
287
break ;
288
288
289
289
}
290
- } else if ( ! ( y === null || y === undefined ) ) {
290
+ } else if ( ! ( y === undefined || y === null || y === "WhyNotAnotherOne" ) ) {
291
291
return {
292
292
x : x . x + y . x ,
293
293
y : x . y + y . y
294
294
} ;
295
295
}
296
- if ( ! ( y === null || y === undefined ) ) {
296
+ if ( ! ( y === undefined || y === null || y === "WhyNotAnotherOne" ) ) {
297
297
return "WhyNotAnotherOne" ;
298
298
}
299
299
switch ( y ) {
@@ -307,7 +307,7 @@ function plus$3(x, y) {
307
307
}
308
308
309
309
function kind$1 ( x ) {
310
- if ( ! ( x === null || x === undefined ) ) {
310
+ if ( ! ( x === undefined || x === null || x === "WhyNotAnotherOne" ) ) {
311
311
return "present" ;
312
312
}
313
313
switch ( x ) {
You can’t perform that action at this time.
0 commit comments