File tree Expand file tree Collapse file tree 3 files changed +54
-15
lines changed
lkql_checker/share/lkql/kp
testsuite/tests/checks/KP-S814-034 Expand file tree Collapse file tree 3 files changed +54
-15
lines changed Original file line number Diff line number Diff line change 1
- # Flag array aggregates with an others choice if the array component type is a
2
- # record type that has a string subcomponent.
1
+ import stdlib
3
2
4
3
@check(message="possible occurrence of KP S814-034", impact="17.*,18.*,19.*")
5
4
fun kp_s814_034(node) =
6
- node is Aggregate
7
- when node.p_expression_type() is t@TypeDecl
8
- when t.p_is_array_type()
9
- and t.p_comp_type().p_is_record_type()
10
- and (from node select first OthersDesignator) != null
11
- and [a for a in (from node select AggregateAssoc)
12
- if a.f_r_expr.p_expression_type().p_root_type()
13
- .p_canonical_fully_qualified_name() == "standard.string"]
5
+ |" Flag array aggregates with an others choice if the array component type is a
6
+ |" record type that has a string subcomponent.
7
+ node is Aggregate(p_is_subaggregate(): false, p_expression_type(): t)
8
+ when
9
+ # Check that the aggregate is not a nested array aggregate
10
+ not node.p_is_subaggregate() and
11
+ t.p_is_array_type() and
12
+ stdlib.any([
13
+ assoc.f_designators is AlternativesList(any children: OthersDesignator)
14
+ for assoc in node.f_assocs.children
15
+ ]) and
16
+
17
+ # Then, ensure the component type is a record and has a String component
18
+ t.p_comp_type().p_is_record_type() and
19
+ stdlib.any([
20
+ t.p_root_type().p_canonical_fully_qualified_name() == "standard.string"
21
+ for t in stdlib.component_types(t.p_comp_type())
22
+ ])
Original file line number Diff line number Diff line change 1
1
procedure P is
2
-
3
2
Max_Error_Length : constant := 8 ;
4
3
subtype Str is String (1 .. Max_Error_Length);
5
4
5
+ S_Init : constant Str := " INIT " ;
6
+
6
7
type Rec is record
7
8
Text : Str;
8
9
end record ;
9
10
11
+ type D_Rec is new Rec with record
12
+ I : Integer;
13
+ end record ;
14
+
15
+ R_Init : constant Rec := (others => S_Init);
16
+
10
17
type Arr is array (1 .. 16 ) of Rec;
18
+ type D_Arr is array (1 .. 16 ) of D_Rec;
19
+ type M_Arr is array (1 .. 2 , 1 .. 2 ) of Rec;
20
+
21
+ type Rec_Arr is record
22
+ A : Arr := (others => (others => S_Init)); -- FLAG
23
+ M_A : M_Arr := (others => (others => R_Init)); -- FLAG
24
+ D_A : D_Arr := (others => (Text => S_Init, I => 2 )); -- FLAG
25
+ end record ;
11
26
12
27
Table : constant Arr :=
13
28
(3 => (Text => " INVALID " ), others => (Text => " OTHERS " )); -- FLAG
14
29
Table2 : constant Arr :=
15
30
(1 => (Text => " VALID " ), 2 => (Text => " OTHERS " )); -- NOFLAG
16
-
17
- end ;
31
+ Table3 : constant Arr :=
32
+ (1 => (others => " VALID " ), 2 => (others => " OTHERS " )); -- NOFLAG
33
+ begin
34
+ null ;
35
+ end P ;
Original file line number Diff line number Diff line change 1
- p.adb:13:6: rule violation: possible occurrence of KP S814-034
2
- 13 | (3 => (Text => "INVALID "), others => (Text => "OTHERS ")); -- FLAG
1
+ p.adb:22:18: rule violation: possible occurrence of KP S814-034
2
+ 22 | A : Arr := (others => (others => S_Init)); -- FLAG
3
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4
+
5
+ p.adb:23:22: rule violation: possible occurrence of KP S814-034
6
+ 23 | M_A : M_Arr := (others => (others => R_Init)); -- FLAG
7
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8
+
9
+ p.adb:24:22: rule violation: possible occurrence of KP S814-034
10
+ 24 | D_A : D_Arr := (others => (Text => S_Init, I => 2)); -- FLAG
11
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12
+
13
+ p.adb:28:6: rule violation: possible occurrence of KP S814-034
14
+ 28 | (3 => (Text => "INVALID "), others => (Text => "OTHERS ")); -- FLAG
3
15
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4
16
You can’t perform that action at this time.
0 commit comments