Skip to content

Commit 4a3fd8f

Browse files
committed
Fix crash when using bitwise not on incompatible type
1 parent 72750a9 commit 4a3fd8f

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

compiler/ml/typecore.ml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3453,9 +3453,15 @@ 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
3461+
| Ctype.Unify trace ->
3462+
raise
3463+
(Error
3464+
(lhs.exp_loc, env, Expr_type_clash {trace; context = None})))
34593465
in
34603466
let targs = [(lhs_label, Some lhs)] in
34613467
Some (targs, result_type)
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/incorrect_tilde_usage.res:2:10
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)