Skip to content

Commit b13884d

Browse files
committed
variant coercion for bigint
1 parent cf62db8 commit b13884d

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

jscomp/ml/variant_coercion.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ let can_coerce_primitive (path : Path.t) =
55
Path.same path Predef.path_string
66
|| Path.same path Predef.path_int
77
|| Path.same path Predef.path_float
8+
|| Path.same path Predef.path_bigint
89

910
let check_paths_same p1 p2 target_path =
1011
Path.same p1 target_path && Path.same p2 target_path
@@ -38,6 +39,8 @@ let variant_has_same_runtime_representation_as_target ~(targetPath : Path.t)
3839
path_same Predef.path_string
3940
|| (* unboxed Number(float) :> float *)
4041
path_same Predef.path_float
42+
|| (* unboxed Bigint(bigint) :> bigint *)
43+
path_same Predef.path_bigint
4144
| Cstr_tuple [] -> (
4245
(* Check that @as payloads match with the target path to coerce to.
4346
No @as means the default encoding, which is string *)

jscomp/test/VariantCoercion.js

Lines changed: 18 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/VariantCoercion.res

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,15 @@ module CoerceFromFloatToVariant = {
8080
let c = 120.
8181
let cc: mixed = (c :> mixed)
8282
}
83+
84+
module CoerceFromBigintToVariant = {
85+
@unboxed type bigints = Bigint(bigint) | @as(1n) First | @as(2n) Second | @as(3n) Third
86+
let a = 100n
87+
let aa = 1n
88+
let b: bigints = (a :> bigints)
89+
let bb: bigints = (aa :> bigints)
90+
91+
@unboxed type mixed = Bigint(bigint) | @as(1n) One | @as(null) Null | Two
92+
let c = 120n
93+
let cc: mixed = (c :> mixed)
94+
}

0 commit comments

Comments
 (0)