if foo.type = 1 then
do_a_thing();
elsif check_value(foo) then
go_another_thing();
elsif foo.type = 3 then
do_a_thing(); -- Issue reported here
end if;
Now, let's suppose that a developer fixed this issue changing the code to this:
if foo.type in (1, 3) then
do_a_thing();
elsif check_value(foo) then
go_another_thing();
end if;
Then we have a behavior change and probably a bug, much harded to track. In the original code, when foo.type = 3 the do_a_thing() procedure is only executed when check_value(foo) is false. In the new code, it is executed always.
The safest option to avoid this problem is make the rule only report an issue when the two branches are consecutive, lile:
if foo.type = 1 then
do_a_thing();
elsif foo.type = 3 then
do_a_thing(); -- Issue reported here
elsif check_value(foo) then
go_another_thing();
end if;
Considering this code:
Now, let's suppose that a developer fixed this issue changing the code to this:
Then we have a behavior change and probably a bug, much harded to track. In the original code, when
foo.type = 3
thedo_a_thing()
procedure is only executed whencheck_value(foo)
isfalse
. In the new code, it is executed always.The safest option to avoid this problem is make the rule only report an issue when the two branches are consecutive, lile: