File tree Expand file tree Collapse file tree 4 files changed +17
-4
lines changed
tests/build_tests/super_errors Expand file tree Collapse file tree 4 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -80,6 +80,7 @@ type type_clash_context =
8080 | TryReturn
8181 | StringConcat
8282 | ComparisonOperator
83+ | WhileCondition
8384 | MathOperator of {
8485 for_float : bool ;
8586 operator : string ;
@@ -110,6 +111,8 @@ let error_expected_type_text ppf type_clash_context =
110111 fprintf ppf " But it's being compared to something of type:"
111112 | Some SwitchReturn -> fprintf ppf " But this switch is expected to return:"
112113 | Some TryReturn -> fprintf ppf " But this try/catch is expected to return:"
114+ | Some WhileCondition ->
115+ fprintf ppf " But a @{<info>while@} loop condition must always be of type:"
113116 | Some IfCondition ->
114117 fprintf ppf " But @{<info>if@} conditions must always be of type:"
115118 | Some IfReturn ->
Original file line number Diff line number Diff line change @@ -1884,7 +1884,6 @@ let rec approx_type env sty =
18841884 | Ptyp_poly (_ , sty ) -> approx_type env sty
18851885 | _ -> newvar ()
18861886
1887- (* TODO: Needs type clash context? *)
18881887let rec type_approx env sexp =
18891888 match sexp.pexp_desc with
18901889 | Pexp_let (_ , _ , e ) -> type_approx env e
@@ -2846,8 +2845,7 @@ and type_expect_ ~context ?in_function ?(recarg = Rejected) env sexp ty_expected
28462845 }
28472846 | Pexp_while (scond , sbody ) ->
28482847 let cond =
2849- (* TODO: Add explicit WhileCondition *)
2850- type_expect ~context: (Some IfCondition ) env scond Predef. type_bool
2848+ type_expect ~context: (Some WhileCondition ) env scond Predef. type_bool
28512849 in
28522850 let body = type_statement ~context: None env sbody in
28532851 rue
@@ -3899,7 +3897,6 @@ and type_cases ~(call_context : [`Switch | `Function | `Try]) ?in_function env
38993897 match pc_guard with
39003898 | None -> None
39013899 | Some scond ->
3902- (* TODO: Add explicit SwitchIfCondition *)
39033900 Some
39043901 (type_expect ~context: (Some IfCondition ) ext_env
39053902 (wrap_unpacks scond unpacks)
Original file line number Diff line number Diff line change 1+
2+ [1;31mWe've found a bug for you![0m
3+ [36m/.../fixtures/while_condition.res[0m:[2m1:7-13[0m
4+
5+ [1;31m1[0m [2m│[0m while [1;31m"horse"[0m {
6+ 2 [2m│[0m Console.log("What")
7+ 3 [2m│[0m }
8+
9+ This has type: [1;31mstring[0m
10+ But a [1;33mwhile[0m loop condition must always be of type: [1;33mbool[0m
Original file line number Diff line number Diff line change 1+ while "horse" {
2+ Console .log ("What" )
3+ }
You can’t perform that action at this time.
0 commit comments