Skip to content

Commit 973351a

Browse files
authored
Fix crash when using bitwise not on incompatible type (#7965)
* Fix crash when using bitwise not on incompatible type * CHANGELOG * Fix comments
1 parent 9616716 commit 973351a

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
- Fix: use configured Jsx module for constraining component return type. https://github.com/rescript-lang/rescript/pull/7945
2626
- Undeprecate `Js_OO` module since it is still used with the `@this` attribute. https://github.com/rescript-lang/rescript/pull/7955
27+
- Fix crash when using bitwise not on incompatible type. https://github.com/rescript-lang/rescript/pull/7965
2728

2829
#### :memo: Documentation
2930

compiler/ml/typecore.ml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3453,9 +3453,14 @@ and translate_unified_ops (env : Env.t) (funct : Typedtree.expression)
34533453
| Tconstr (path, _, _), {string = Some _}
34543454
when Path.same path Predef.path_string ->
34553455
instance_def Predef.type_string
3456-
| _ ->
3457-
unify env lhs_type (instance_def Predef.type_int);
3458-
instance_def Predef.type_int
3456+
| _ -> (
3457+
try
3458+
unify env lhs_type (instance_def Predef.type_int);
3459+
instance_def Predef.type_int
3460+
with Ctype.Unify trace ->
3461+
raise
3462+
(Error (lhs.exp_loc, env, Expr_type_clash {trace; context = None}))
3463+
)
34593464
in
34603465
let targs = [(lhs_label, Some lhs)] in
34613466
Some (targs, result_type)

compiler/syntax/src/res_token.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ type t =
7777
| Of
7878
| Land
7979
| Lor
80-
| Bnot (* Bitwise and: ~~~ *)
81-
| Bor (* Bitwise and: ||| *)
82-
| Bxor (* Bitwise and: ^^^ *)
80+
| Bnot (* Bitwise not: ~~~ *)
81+
| Bor (* Bitwise or: ||| *)
82+
| Bxor (* Bitwise xor: ^^^ *)
8383
| Band (* Bitwise and: &&& *)
8484
| Caret
8585
| BangEqual
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/bitnot_type_mismatch.res:2:12
4+
5+
1 │ let x = []
6+
2 │ let _ = ~~~x
7+
3 │
8+
9+
This has type: array<'a>
10+
But it's expected to have type: int
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let x = []
2+
let _ = ~~~x

0 commit comments

Comments
 (0)