Skip to content

Commit e05abdf

Browse files
committed
assert condition
1 parent a5f1d7c commit e05abdf

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

compiler/ml/error_message_utils.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ type type_clash_context =
7575
| ArrayValue
7676
| MaybeUnwrapOption
7777
| IfCondition
78+
| AssertCondition
7879
| IfReturn
7980
| SwitchReturn
8081
| TryReturn
@@ -118,6 +119,7 @@ let error_expected_type_text ppf type_clash_context =
118119
fprintf ppf "But a @{<info>for@} loop bounds must always be of type:"
119120
| Some IfCondition ->
120121
fprintf ppf "But @{<info>if@} conditions must always be of type:"
122+
| Some AssertCondition -> fprintf ppf "But assertions must always be of type:"
121123
| Some IfReturn ->
122124
fprintf ppf "But this @{<info>if@} statement is expected to return:"
123125
| Some ArrayValue ->

compiler/ml/typecore.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3068,8 +3068,9 @@ and type_expect_ ~context ?in_function ?(recarg = Rejected) env sexp ty_expected
30683068
exp_env = env;
30693069
}
30703070
| Pexp_assert e ->
3071-
(* TODO: Add explicit AssertCondition *)
3072-
let cond = type_expect ~context:(Some IfCondition) env e Predef.type_bool in
3071+
let cond =
3072+
type_expect ~context:(Some AssertCondition) env e Predef.type_bool
3073+
in
30733074
let exp_type =
30743075
match cond.exp_desc with
30753076
| Texp_construct (_, {cstr_name = "false"}, _) -> instance env ty_expected
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/assert_condition.res:1:8-14
4+
5+
1 │ assert("horse")
6+
2 │
7+
8+
This has type: string
9+
But assertions must always be of type: bool

tests/build_tests/super_errors/expected/for_loop_condition.res.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22
We've found a bug for you!
3-
/.../fixtures/for_loop_condition.res:1:16-19
3+
/.../fixtures/for_loop_condition.res:1:15-18
44

5-
1 │ for (x in 0 to "10") {
5+
1 │ for x in 0 to "10" {
66
2 │ Console.log(x)
77
3 │ }
88

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
assert("horse")

0 commit comments

Comments
 (0)