@@ -22,6 +22,7 @@ type untaggedError =
22
22
| AtMostOneFunction
23
23
| AtMostOneString
24
24
| AtMostOneNumber
25
+ | AtMostOneBigint
25
26
| AtMostOneBoolean
26
27
| DuplicateLiteral of string
27
28
| ConstructorMoreThanOneArg of string
@@ -54,6 +55,8 @@ let report_error ppf =
54
55
| AtMostOneBoolean -> " At most one case can be a boolean type."
55
56
| AtMostOneNumber ->
56
57
" At most one case can be a number type (int or float)."
58
+ | AtMostOneBigint ->
59
+ " At most one case can be a bigint type."
57
60
| DuplicateLiteral s -> " Duplicate literal " ^ s ^ " ."
58
61
| ConstructorMoreThanOneArg (name ) -> " Constructor " ^ name ^ " has more than one argument." )
59
62
@@ -62,6 +65,7 @@ type block_type =
62
65
| IntType
63
66
| StringType
64
67
| FloatType
68
+ | BigintType
65
69
| BooleanType
66
70
| InstanceType of Instance .t
67
71
| FunctionType
@@ -77,6 +81,7 @@ type tag_type =
77
81
| String of string
78
82
| Int of int
79
83
| Float of string
84
+ | Bigint of string
80
85
| Bool of bool
81
86
| Null
82
87
| Undefined (* literal or tagged block *)
@@ -119,6 +124,9 @@ let process_tag_type (attrs : Parsetree.attributes) =
119
124
(match Ast_payload. is_single_float payload with
120
125
| None -> ()
121
126
| Some f -> st := Some (Float f));
127
+ (match Ast_payload. is_single_bigint payload with
128
+ | None -> ()
129
+ | Some i -> st := Some (Bigint i));
122
130
(match Ast_payload. is_single_bool payload with
123
131
| None -> ()
124
132
| Some b -> st := Some (Bool b));
@@ -172,6 +180,8 @@ let get_block_type_from_typ ~env (t: Types.type_expr) : block_type option =
172
180
Some IntType
173
181
| {desc = Tconstr (path , _ , _ )} when Path. same path Predef. path_float ->
174
182
Some FloatType
183
+ | {desc = Tconstr (path , _ , _ )} when Path. same path Predef. path_bigint ->
184
+ Some BigintType
175
185
| {desc = Tconstr (path , _ , _ )} when Path. same path Predef. path_bool ->
176
186
Some BooleanType
177
187
| ({desc = Tconstr _ } as t ) when Ast_uncurried_utils. typeIsUncurriedFun t ->
@@ -240,6 +250,7 @@ let checkInvariant ~isUntaggedDef ~(consts : (Location.t * tag) list)
240
250
let objectTypes = ref 0 in
241
251
let stringTypes = ref 0 in
242
252
let numberTypes = ref 0 in
253
+ let bigintTypes = ref 0 in
243
254
let booleanTypes = ref 0 in
244
255
let unknownTypes = ref 0 in
245
256
let addStringLiteral ~loc s =
@@ -267,6 +278,9 @@ let checkInvariant ~isUntaggedDef ~(consts : (Location.t * tag) list)
267
278
raise (Error (loc, InvalidUntaggedVariantDefinition AtMostOneString ));
268
279
if ! numberTypes > 1 then
269
280
raise (Error (loc, InvalidUntaggedVariantDefinition AtMostOneNumber ));
281
+ if ! bigintTypes > 1 then
282
+ (* FIXME need to define another error for duplicated bigint *)
283
+ raise (Error (loc, InvalidUntaggedVariantDefinition AtMostOneBigint ));
270
284
if ! booleanTypes > 1 then
271
285
raise (Error (loc, InvalidUntaggedVariantDefinition AtMostOneBoolean ));
272
286
if ! booleanTypes > 0 && (StringSet. mem " true" ! nonstring_literals || StringSet. mem " false" ! nonstring_literals) then
@@ -278,6 +292,7 @@ let checkInvariant ~isUntaggedDef ~(consts : (Location.t * tag) list)
278
292
| Some (String s ) -> addStringLiteral ~loc s
279
293
| Some (Int i ) -> addNonstringLiteral ~loc (string_of_int i)
280
294
| Some (Float f ) -> addNonstringLiteral ~loc f
295
+ | Some (Bigint i ) -> addNonstringLiteral ~loc i
281
296
| Some Null -> addNonstringLiteral ~loc " null"
282
297
| Some Undefined -> addNonstringLiteral ~loc " undefined"
283
298
| Some (Bool b ) -> addNonstringLiteral ~loc (if b then " true" else " false" )
@@ -295,6 +310,7 @@ let checkInvariant ~isUntaggedDef ~(consts : (Location.t * tag) list)
295
310
Hashtbl. replace instanceTypes i (count + 1 );
296
311
| FunctionType -> incr functionTypes;
297
312
| (IntType | FloatType ) -> incr numberTypes;
313
+ | BigintType -> incr bigintTypes;
298
314
| BooleanType -> incr booleanTypes;
299
315
| StringType -> incr stringTypes;
300
316
);
@@ -359,6 +375,9 @@ module DynamicChecks = struct
359
375
let function_ = Untagged FunctionType |> tag_type
360
376
let string = Untagged StringType |> tag_type
361
377
let number = Untagged IntType |> tag_type
378
+
379
+ let bigint = Untagged BigintType |> tag_type
380
+
362
381
let boolean = Untagged BooleanType |> tag_type
363
382
364
383
let ( == ) x y = bin EqEqEq x y
@@ -375,7 +394,7 @@ module DynamicChecks = struct
375
394
in
376
395
let literals_overlaps_with_number () =
377
396
Ext_list. exists literal_cases (function
378
- | Int _ | Float _ -> true
397
+ | Int _ | Float _ | Bigint _ -> true
379
398
| _ -> false )
380
399
in
381
400
let literals_overlaps_with_boolean () =
@@ -398,6 +417,8 @@ module DynamicChecks = struct
398
417
typeof e != number
399
418
| FloatType when literals_overlaps_with_number () = false ->
400
419
typeof e != number
420
+ | BigintType when literals_overlaps_with_number () = false ->
421
+ typeof e != bigint
401
422
| BooleanType when literals_overlaps_with_boolean () = false ->
402
423
typeof e != boolean
403
424
| InstanceType i -> not (is_instance i e)
@@ -408,6 +429,7 @@ module DynamicChecks = struct
408
429
| StringType (* overlap *)
409
430
| IntType (* overlap *)
410
431
| FloatType (* overlap *)
432
+ | BigintType (* overlap *)
411
433
| BooleanType (* overlap *)
412
434
| UnknownType -> (
413
435
(* We don't know the type of unknown, so we need to express:
@@ -449,7 +471,7 @@ module DynamicChecks = struct
449
471
let add_runtime_type_check ~tag_type ~(block_cases : block_type list ) x y =
450
472
let instances = Ext_list. filter_map block_cases (function InstanceType i -> Some i | _ -> None ) in
451
473
match tag_type with
452
- | Untagged (IntType | StringType | FloatType | BooleanType | FunctionType ) ->
474
+ | Untagged (IntType | StringType | FloatType | BigintType | BooleanType | FunctionType ) ->
453
475
typeof y == x
454
476
| Untagged ObjectType ->
455
477
if instances <> [] then
@@ -462,5 +484,5 @@ module DynamicChecks = struct
462
484
| Untagged UnknownType ->
463
485
(* This should not happen because unknown must be the only non-literal case *)
464
486
assert false
465
- | Bool _ | Float _ | Int _ | String _ | Null | Undefined -> x
487
+ | Bool _ | Float _ | Int _ | Bigint _ | String _ | Null | Undefined -> x
466
488
end
0 commit comments