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 =
80
80
| TryReturn
81
81
| StringConcat
82
82
| ComparisonOperator
83
+ | WhileCondition
83
84
| MathOperator of {
84
85
for_float : bool ;
85
86
operator : string ;
@@ -110,6 +111,8 @@ let error_expected_type_text ppf type_clash_context =
110
111
fprintf ppf " But it's being compared to something of type:"
111
112
| Some SwitchReturn -> fprintf ppf " But this switch is expected to return:"
112
113
| 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:"
113
116
| Some IfCondition ->
114
117
fprintf ppf " But @{<info>if@} conditions must always be of type:"
115
118
| Some IfReturn ->
Original file line number Diff line number Diff line change @@ -1884,7 +1884,6 @@ let rec approx_type env sty =
1884
1884
| Ptyp_poly (_ , sty ) -> approx_type env sty
1885
1885
| _ -> newvar ()
1886
1886
1887
- (* TODO: Needs type clash context? *)
1888
1887
let rec type_approx env sexp =
1889
1888
match sexp.pexp_desc with
1890
1889
| Pexp_let (_ , _ , e ) -> type_approx env e
@@ -2846,8 +2845,7 @@ and type_expect_ ~context ?in_function ?(recarg = Rejected) env sexp ty_expected
2846
2845
}
2847
2846
| Pexp_while (scond , sbody ) ->
2848
2847
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
2851
2849
in
2852
2850
let body = type_statement ~context: None env sbody in
2853
2851
rue
@@ -3899,7 +3897,6 @@ and type_cases ~(call_context : [`Switch | `Function | `Try]) ?in_function env
3899
3897
match pc_guard with
3900
3898
| None -> None
3901
3899
| Some scond ->
3902
- (* TODO: Add explicit SwitchIfCondition *)
3903
3900
Some
3904
3901
(type_expect ~context: (Some IfCondition ) ext_env
3905
3902
(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