Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

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

#### :memo: Documentation

Expand Down
11 changes: 8 additions & 3 deletions compiler/ml/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3453,9 +3453,14 @@ and translate_unified_ops (env : Env.t) (funct : Typedtree.expression)
| Tconstr (path, _, _), {string = Some _}
when Path.same path Predef.path_string ->
instance_def Predef.type_string
| _ ->
unify env lhs_type (instance_def Predef.type_int);
instance_def Predef.type_int
| _ -> (
try
unify env lhs_type (instance_def Predef.type_int);
instance_def Predef.type_int
with Ctype.Unify trace ->
raise
(Error (lhs.exp_loc, env, Expr_type_clash {trace; context = None}))
)
Comment on lines +3456 to +3463
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed now but wasn't before...?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was always needed, but for a long time nobody noticed that it would crash if you passed a non-matching type, until this was reported in #7960.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right. Good catch then!

in
let targs = [(lhs_label, Some lhs)] in
Some (targs, result_type)
Expand Down
6 changes: 3 additions & 3 deletions compiler/syntax/src/res_token.ml
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ type t =
| Of
| Land
| Lor
| Bnot (* Bitwise and: ~~~ *)
| Bor (* Bitwise and: ||| *)
| Bxor (* Bitwise and: ^^^ *)
| Bnot (* Bitwise not: ~~~ *)
| Bor (* Bitwise or: ||| *)
| Bxor (* Bitwise xor: ^^^ *)
| Band (* Bitwise and: &&& *)
| Caret
| BangEqual
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

We've found a bug for you!
/.../fixtures/bitnot_type_mismatch.res:2:12

1 │ let x = []
2 │ let _ = ~~~x
3 │

This has type: array<'a>
But it's expected to have type: int
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let x = []
let _ = ~~~x
Loading