Skip to content

Commit ca17026

Browse files
committed
Merge branch 'topic/449' into 'master'
Fix metrics.lkql's statement_complexity regarding SelectStmt Closes #449 See merge request eng/libadalang/langkit-query-language!412
2 parents 3c439a2 + baf314d commit ca17026

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

lkql_checker/share/lkql/metrics.lkql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fun statement_complexity(body, exempt_case=false) =
3939
| e@ExitStmt(f_cond_expr: not null) => 1
4040
| s@SelectStmt(
4141
f_guards: guards,
42-
f_else_stmts: elses_stmts,
42+
f_else_part: elses_stmts,
4343
f_then_abort_part: then_abort_part
4444
) => guards.children_count
4545
+ (if elses_stmts.children_count == 0 then 0 else 1)

testsuite/tests/checks/metrics_cyclomatic/proc.adb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,33 @@ procedure Proc (I : in out Integer; S : String) is -- FLAG Complexity 7
3636
when 2 => null;
3737
when 3 => null;
3838
when 4 => null;
39-
when others => I := if I > 0 then 1 elsif False then 2 else 3;
39+
when others => I := (if I > 0 then 1 elsif False then 2 else 3);
4040
end case;
4141
end E1;
4242
end Prot;
4343

44+
task U is
45+
entry E1;
46+
entry E2;
47+
entry E3;
48+
entry E4;
49+
end U;
50+
51+
task body U is -- FLAG Complexity 6
52+
begin
53+
select
54+
accept E1;
55+
or
56+
accept E2;
57+
or
58+
accept E3;
59+
or
60+
accept E4;
61+
or
62+
terminate;
63+
end select;
64+
end U;
65+
4466
begin
4567
if I in 1 .. 10 then
4668
for J in S'Range loop

testsuite/tests/checks/metrics_cyclomatic/test.out

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ proc.adb:1:1: rule violation: cyclomatic complexity is too high: 7
22
1 | procedure Proc (I : in out Integer; S : String) is -- FLAG Complexity 7
33
| _^
44
||
5-
|| ~~~ 58 other lines ~~~
5+
|| ~~~ 80 other lines ~~~
66
||
7-
60 || end Proc;
7+
82 || end Proc;
88
||_________^
99

1010
proc.adb:8:4: rule violation: cyclomatic complexity is too high: 6
@@ -34,3 +34,12 @@ proc.adb:32:7: rule violation: cyclomatic complexity is too high: 7
3434
41 || end E1;
3535
||_____________^
3636

37+
proc.adb:51:4: rule violation: cyclomatic complexity is too high: 6
38+
51 | task body U is -- FLAG Complexity 6
39+
| ____^
40+
||
41+
|| ~~~ 12 other lines ~~~
42+
||
43+
64 || end U;
44+
||_________^
45+

0 commit comments

Comments
 (0)