Skip to content

Commit 8ef9b9e

Browse files
committed
Raising_External_Exceptions: do not flag internally caught exceptions
1 parent 1e4bde7 commit 8ef9b9e

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

lkql_checker/share/lkql/raising_external_exceptions.lkql

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import stdlib
2+
13
# TODO: share is_predefined_exception with raising_predefined_exception
24
fun is_predefined_exception(e) = {
35
val name = e.p_defining_name().p_canonical_fully_qualified_name();
@@ -7,9 +9,24 @@ fun is_predefined_exception(e) = {
79
name == "standard.tasking_error"
810
}
911

12+
fun internal_catch(n) =
13+
|" Return whether the current RaiseStmt is locally caught.
14+
n is *(
15+
any parent: stmts@HandledStmts
16+
when stmts.f_exceptions is *(
17+
any children: eh@ExceptionHandler
18+
when stdlib.any([
19+
ex_name is OthersDesignator
20+
or ex_name.p_referenced_decl() == n.f_exception_name.p_referenced_decl()
21+
for ex_name in eh.f_handled_exceptions.children
22+
])
23+
)
24+
)
25+
1026
fun check_raise(n, lib) = {
1127
val e = n.f_exception_name.p_referenced_decl();
1228
not (is_predefined_exception(e)
29+
or internal_catch(n)
1330
or e is *(all parent: not PrivatePart,
1431
any parent: exc_lib@LibraryItem when exc_lib == lib))
1532
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package body Test is
2+
package body Pack is
3+
Exception_2 : exception;
4+
Exception_3 : exception;
5+
procedure Proc_0 is
6+
begin
7+
raise Exception_0;
8+
end Proc_0;
9+
procedure Proc_1 is
10+
begin
11+
raise Exception_1;
12+
end Proc_1;
13+
procedure Proc_2 is
14+
begin
15+
raise Exception_2; -- FLAG
16+
end Proc_2;
17+
procedure Proc_3 is
18+
begin
19+
raise Exception_3;
20+
exception
21+
when Exception_3 =>
22+
null;
23+
end Proc_3;
24+
procedure Proc_4 is
25+
begin
26+
raise Exception_3;
27+
exception
28+
when others =>
29+
null;
30+
end Proc_4;
31+
end Pack;
32+
33+
package body Pack_G is
34+
Exception_G2 : exception;
35+
Exception_G3 : exception;
36+
Exception_G4 : exception;
37+
procedure Proc_G0 is
38+
begin
39+
raise Exception_0;
40+
end Proc_G0;
41+
procedure Proc_G1 is
42+
begin
43+
raise Exception_G1;
44+
end Proc_G1;
45+
procedure Proc_G2 is
46+
begin
47+
raise Exception_G2; -- FLAG
48+
end Proc_G2;
49+
procedure Proc_G3 is
50+
begin
51+
raise Exception_G4;
52+
exception
53+
when Exception_G3 | Exception_G4 =>
54+
null;
55+
end Proc_G3;
56+
end Pack_G;
57+
end Test;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package Test is
2+
Exception_0 : exception;
3+
package Pack is
4+
Exception_1 : exception;
5+
procedure Proc_1;
6+
end Pack;
7+
generic
8+
package Pack_G is
9+
Exception_G1 : exception;
10+
procedure Proc_G1;
11+
end Pack_G;
12+
end Test;

testsuite/tests/checks/raise_external/test.out

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,11 @@ foo.adb:6:10: rule violation: raised exception is not declared in visible part o
22
6 | raise Exception_Declarations.Ex; -- FLAG
33
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44

5+
test.adb:15:10: rule violation: raised exception is not declared in visible part of enclosing library package
6+
15 | raise Exception_2; -- FLAG
7+
| ^^^^^^^^^^^^^^^^^^
8+
9+
test.adb:47:10: rule violation: raised exception is not declared in visible part of enclosing library package
10+
47 | raise Exception_G2; -- FLAG
11+
| ^^^^^^^^^^^^^^^^^^^
12+

0 commit comments

Comments
 (0)