File tree Expand file tree Collapse file tree 2 files changed +8
-4
lines changed
testsuite/tests/checks/use_if_expressions Expand file tree Collapse file tree 2 files changed +8
-4
lines changed Original file line number Diff line number Diff line change 1- fun simple_return(l) = l.children_count == 1 and l[1] is ReturnStmt
1+ fun simple_return(l) = l != null and l .children_count == 1 and l[1] is ReturnStmt
22fun simple_assignment(l) =
3- l.children_count == 1 and l[1] is AssignStmt(f_dest: Name)
3+ l != null and l .children_count == 1 and l[1] is AssignStmt(f_dest: Name)
44
55@check(message="IF statement may be replaced by an IF expression",
66 category="Style", subcategory="Programming Practice")
@@ -52,11 +52,11 @@ fun use_if_expressions(node) =
5252 |" end if;
5353 node is IfStmt
5454 when (simple_return(node.f_then_stmts) and
55- simple_return(node.f_else_part.f_stmts) and
55+ simple_return(node.f_else_part? .f_stmts) and
5656 not [s for s in node.f_alternatives.children
5757 if not simple_return(s.f_stmts)])
5858 or (simple_assignment(node.f_then_stmts) and
59- simple_assignment(node.f_else_part.f_stmts) and
59+ simple_assignment(node.f_else_part? .f_stmts) and
6060 not [s for s in node.f_alternatives.children
6161 if not simple_assignment(s.f_stmts)] and {
6262 val stmts = from node select AssignStmt;
Original file line number Diff line number Diff line change 4545 X := 0 ;
4646 end if ;
4747
48+ if X > 0 then -- NOFLAG
49+ return 2 ;
50+ end if :
51+
4852 return X;
4953end Stmt ;
You can’t perform that action at this time.
0 commit comments