Skip to content

Commit 30ab76c

Browse files
committed
version without parentheses
1 parent 33f84b3 commit 30ab76c

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src-json/warning.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
},
7676
{
7777
"name": "WConditionAssign",
78-
"doc": "Using the result of an assignment as a condition without parentheses",
78+
"doc": "Using the result of an assignment as a condition",
7979
"parent": "WTyper"
8080
},
8181
{

src/typing/typer.ml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,18 +1475,15 @@ and make_if_then_else ctx e0 e1 e2 with_type p =
14751475
mk (TIf (e0,e1,Some e2)) t p
14761476

14771477
and warn_assign_in_condition ctx cond =
1478-
let rec skip_without_parentheses e = match e.eexpr with
1479-
| TMeta(_,e1) | TBlock [e1] | TCast(e1,None) -> skip e1
1480-
| _ -> e in
14811478
let rec is_assign e =
1482-
let e = skip_without_parentheses e in
1479+
let e = Texpr.skip e in
14831480
match e.eexpr with
14841481
| TBinop (OpAssign, _, rhs) ->
14851482
let t = follow rhs.etype in
14861483
let is_bool = ExtType.is_bool t in
1487-
let is_null = match (skip_without_parentheses rhs).eexpr with | TConst TNull -> true | _ -> false in
1484+
let is_null = match (Texpr.skip rhs).eexpr with | TConst TNull -> true | _ -> false in
14881485
if is_bool || is_null then
1489-
warning ctx WConditionAssign "Using the result of an assignment as a condition without parentheses" e.epos
1486+
warning ctx WConditionAssign "Using the result of an assignment as a condition" e.epos
14901487
| TBinop ((OpBoolAnd | OpBoolOr), e1, e2) ->
14911488
is_assign e1;
14921489
is_assign e2;
@@ -1504,7 +1501,6 @@ and type_if ctx e e1 e2 with_type is_ternary p =
15041501
let e = type_expr ctx e WithType.value in
15051502
if is_ternary then begin match e.eexpr with
15061503
| TConst TNull -> raise_typing_error "Cannot use null as ternary condition" e.epos
1507-
| TParenthesis e -> warn_assign_in_condition ctx e;
15081504
| _ -> ()
15091505
end;
15101506
warn_assign_in_condition ctx e;

0 commit comments

Comments
 (0)