Skip to content

Commit ef7b6ba

Browse files
committed
Fix positional_generic_parameter rule
The rule was failing in case a generic instantiation with only one parameter refered to a generic renaming declaration. This change also fixes how generic formal parameters are counted.
1 parent d311673 commit ef7b6ba

File tree

3 files changed

+117
-7
lines changed

3 files changed

+117
-7
lines changed

lkql_checker/share/lkql/positional_generic_parameters.lkql

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1+
fun follow_renamings(gen_decl) =
2+
|" If gen_decl is a renaming declaration, return the renamed generic
3+
|" declaration, gen_decl otherwise.
4+
match gen_decl
5+
| r@GenericRenamingDecl => r.f_renames.p_referenced_decl()
6+
| * => gen_decl
7+
18
fun check_generic(n) =
29
|" Return true if the generic decl corresponding to n contains more than 1
310
|" formal parameter.
4-
[
11+
reduce([
512
(
613
match x.f_decl
714
| d@(ObjectDecl | NumberDecl) => d.f_ids.children_count
8-
| * => 1
15+
| * => 1
916
)
10-
for x in from n.p_referenced_decl().f_formal_part.f_decls select GenericFormal
11-
].length > 1
17+
for x in from follow_renamings(n).f_formal_part.f_decls select GenericFormal
18+
], (acc, cur) => acc + cur, 0) > 1
1219

1320
fun add_param_name(param, ctx) =
1421
ctx.set_child(
@@ -48,6 +55,5 @@ fun positional_generic_parameters(node) =
4855
)
4956
when l.children_count > 1
5057
or match g
51-
| p@GenericSubpInstantiation => check_generic(p.f_generic_subp_name)
52-
| p@GenericPackageInstantiation => check_generic(p.f_generic_pkg_name)
53-
| * => false
58+
| g@GenericInstantiation => check_generic(g.p_designated_generic_decl())
59+
| * => false

testsuite/tests/checks/positional_generic_parameters/pos.adb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,38 @@ procedure Pos (I : in out Integer) is
1010
(My_Int, Integer); -- FLAG (2)
1111

1212
package My_Int_IO is new Ada.Text_IO.Integer_IO (My_Int); -- NOFLAG
13+
14+
generic
15+
A, B, C : Integer;
16+
package G is
17+
end G;
18+
19+
package I_G_1 is new G (1, 2, 3); -- FLAG (3)
20+
package I_G_2 is new G (1, 2, C => 3); -- FLAG (2)
21+
package I_G_3 is new G (1, C => 2, B => 3); -- FLAG (1)
22+
23+
generic package R_G renames G;
24+
25+
package I_RG is new R_G (1, 2, 3); -- FLAG (3)
26+
27+
generic
28+
A : Integer;
29+
package H is
30+
end H;
31+
32+
package I_H is new H (1); -- NOFLAG
33+
34+
generic package R_H renames H;
35+
36+
package I_RH is new R_H (1); -- NOFLAG
37+
38+
generic
39+
A, B, C : Integer := 0;
40+
package D is
41+
end D;
42+
43+
package I_D is new D (1); -- FLAG
44+
1345
begin
1446
null;
1547
end Pos;

testsuite/tests/checks/positional_generic_parameters/test.out

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,46 @@ pos.adb:10:15: rule violation: positional generic association
66
10 | (My_Int, Integer); -- FLAG (2)
77
| ^^^^^^^
88

9+
pos.adb:19:28: rule violation: positional generic association
10+
19 | package I_G_1 is new G (1, 2, 3); -- FLAG (3)
11+
| ^
12+
13+
pos.adb:19:31: rule violation: positional generic association
14+
19 | package I_G_1 is new G (1, 2, 3); -- FLAG (3)
15+
| ^
16+
17+
pos.adb:19:34: rule violation: positional generic association
18+
19 | package I_G_1 is new G (1, 2, 3); -- FLAG (3)
19+
| ^
20+
21+
pos.adb:20:28: rule violation: positional generic association
22+
20 | package I_G_2 is new G (1, 2, C => 3); -- FLAG (2)
23+
| ^
24+
25+
pos.adb:20:31: rule violation: positional generic association
26+
20 | package I_G_2 is new G (1, 2, C => 3); -- FLAG (2)
27+
| ^
28+
29+
pos.adb:21:28: rule violation: positional generic association
30+
21 | package I_G_3 is new G (1, C => 2, B => 3); -- FLAG (1)
31+
| ^
32+
33+
pos.adb:25:29: rule violation: positional generic association
34+
25 | package I_RG is new R_G (1, 2, 3); -- FLAG (3)
35+
| ^
36+
37+
pos.adb:25:32: rule violation: positional generic association
38+
25 | package I_RG is new R_G (1, 2, 3); -- FLAG (3)
39+
| ^
40+
41+
pos.adb:25:35: rule violation: positional generic association
42+
25 | package I_RG is new R_G (1, 2, 3); -- FLAG (3)
43+
| ^
44+
45+
pos.adb:43:26: rule violation: positional generic association
46+
43 | package I_D is new D (1); -- FLAG
47+
| ^
48+
949
Patched "pos.adb":
1050
==================
1151

@@ -21,6 +61,38 @@ procedure Pos (I : in out Integer) is
2161
(Source=>My_Int, Target=>Integer); -- FLAG (2)
2262

2363
package My_Int_IO is new Ada.Text_IO.Integer_IO (My_Int); -- NOFLAG
64+
65+
generic
66+
A, B, C : Integer;
67+
package G is
68+
end G;
69+
70+
package I_G_1 is new G (A=>1, B=>2, C=>3); -- FLAG (3)
71+
package I_G_2 is new G (A=>1, B=>2, C => 3); -- FLAG (2)
72+
package I_G_3 is new G (A=>1, C => 2, B => 3); -- FLAG (1)
73+
74+
generic package R_G renames G;
75+
76+
package I_RG is new R_G (A=>1, B=>2, C=>3); -- FLAG (3)
77+
78+
generic
79+
A : Integer;
80+
package H is
81+
end H;
82+
83+
package I_H is new H (1); -- NOFLAG
84+
85+
generic package R_H renames H;
86+
87+
package I_RH is new R_H (1); -- NOFLAG
88+
89+
generic
90+
A, B, C : Integer := 0;
91+
package D is
92+
end D;
93+
94+
package I_D is new D (A=>1); -- FLAG
95+
2496
begin
2597
null;
2698
end Pos;

0 commit comments

Comments
 (0)