Skip to content

Commit 3030ff9

Browse files
committed
Handle more cases
1 parent e238013 commit 3030ff9

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

jscomp/core/lam.ml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ end
468468

469469
let prim ~primitive:(prim : Lam_primitive.t) ~args loc : t =
470470
let default () : t = Lprim { primitive = prim; args; loc } in
471+
(* extract the runtime representation if possible *)
471472
let extract_const_as c def =
472473
(match c with
473474
| Lam_constant.Pt_constructor({cstr_name = ({tag_type = Some(Int(v))})}) -> Int32.of_int v
@@ -494,8 +495,10 @@ let prim ~primitive:(prim : Lam_primitive.t) ~args loc : t =
494495
| _ -> default ())
495496
| [ Lconst a; Lconst b ] -> (
496497
match (prim, a, b) with
497-
| Pintcomp cmp, Const_int a, Const_int b ->
498-
Lift.bool (Lam_compat.cmp_int32 cmp a.i b.i)
498+
| Pintcomp cmp, Const_int {i = aa; comment = aa_pointer_info}, Const_int {i = bb; comment = bb_pointer_info} ->
499+
let aa = extract_const_as aa_pointer_info aa in
500+
let bb = extract_const_as bb_pointer_info bb in
501+
Lift.bool (Lam_compat.cmp_int32 cmp aa bb)
499502
| Pfloatcomp cmp, Const_float a, Const_float b ->
500503
(* FIXME: could raise? *)
501504
Lift.bool
@@ -540,7 +543,8 @@ let prim ~primitive:(prim : Lam_primitive.t) ~args loc : t =
540543
Lift.string (a ^ b)
541544
| ( (Pstringrefs | Pstringrefu),
542545
Const_string { s = a; unicode = false },
543-
Const_int { i = b } ) -> (
546+
Const_int { i = b; comment = pointer_info } ) -> (
547+
let b = extract_const_as pointer_info b in
544548
try Lift.char (Char.code (String.get a (Int32.to_int b))) with _ -> default ())
545549
| _ -> default ())
546550
| _ -> (

jscomp/test/VariantCoercion.js

Lines changed: 1 addition & 0 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ module CoerceVariantBinaryOp = {
126126

127127
let x1 = 0->lor((B :> int))
128128
let x2 = -(B :> int)
129+
let x3 = 2 == (B :> int)
129130

130131
type flagStr = | @as("one") One | @as("two") Two
131132

0 commit comments

Comments
 (0)