diff --git a/CHANGELOG.md b/CHANGELOG.md index b457cf5759..89aa36005a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/compiler/ml/typecore.ml b/compiler/ml/typecore.ml index f0f7b09009..ee304dff7d 100644 --- a/compiler/ml/typecore.ml +++ b/compiler/ml/typecore.ml @@ -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})) + ) in let targs = [(lhs_label, Some lhs)] in Some (targs, result_type) diff --git a/compiler/syntax/src/res_token.ml b/compiler/syntax/src/res_token.ml index ffd85f7f4f..192c976ab3 100644 --- a/compiler/syntax/src/res_token.ml +++ b/compiler/syntax/src/res_token.ml @@ -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 diff --git a/tests/build_tests/super_errors/expected/bitnot_type_mismatch.res.expected b/tests/build_tests/super_errors/expected/bitnot_type_mismatch.res.expected new file mode 100644 index 0000000000..0407477f9a --- /dev/null +++ b/tests/build_tests/super_errors/expected/bitnot_type_mismatch.res.expected @@ -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 \ No newline at end of file diff --git a/tests/build_tests/super_errors/fixtures/bitnot_type_mismatch.res b/tests/build_tests/super_errors/fixtures/bitnot_type_mismatch.res new file mode 100644 index 0000000000..543aa91543 --- /dev/null +++ b/tests/build_tests/super_errors/fixtures/bitnot_type_mismatch.res @@ -0,0 +1,2 @@ +let x = [] +let _ = ~~~x