Skip to content

Commit e5dd488

Browse files
committed
Merge branch 'topic/rules/fix_identifier_prefixes' into 'master'
Restore old behavior of the "Identifier_Prefixes" rule regarding formal object declarations Closes #530 See merge request eng/libadalang/langkit-query-language!518
2 parents 683c59c + 2faacb0 commit e5dd488

File tree

4 files changed

+44
-21
lines changed

4 files changed

+44
-21
lines changed

lkql_checker/doc/generated/predefined_rules.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5724,7 +5724,13 @@ rule options files:
57245724
*Constant: string*
57255725
Specifies the prefix for defining names from constants and named number
57265726
declarations, including the object renaming declaration if the
5727-
renamed object is a constant
5727+
renamed object is a constant.
5728+
5729+
.. attention::
5730+
For legacy reasons, formal object declarations are not
5731+
considered constant, even if they are declared with the ``in`` mode. Consequently,
5732+
this rule will flag each generic formal object declarations that have the prefix
5733+
specified by this parameter value.
57285734

57295735
*Enum: string*
57305736
Specifies the prefix for defining enumeration literals and for the

lkql_checker/share/lkql/identifier_prefixes.lkql

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,13 @@ fun identifier_prefixes(
9999
|" *Constant: string*
100100
|" Specifies the prefix for defining names from constants and named number
101101
|" declarations, including the object renaming declaration if the
102-
|" renamed object is a constant
102+
|" renamed object is a constant.
103+
|"
104+
|" .. attention::
105+
|" For legacy reasons, formal object declarations are not
106+
|" considered constant, even if they are declared with the ``in`` mode. Consequently,
107+
|" this rule will flag each generic formal object declarations that have the prefix
108+
|" specified by this parameter value.
103109
|"
104110
|" *Enum: string*
105111
|" Specifies the prefix for defining enumeration literals and for the
@@ -385,7 +391,7 @@ fun identifier_prefixes(
385391
| p => match p.parent
386392
# Constants
387393
| (
388-
ObjectDecl(p_is_constant_object(): true)
394+
ObjectDecl(p_is_constant_object(): true, parent: not GenericFormalObjDecl)
389395
| NumberDecl
390396
) =>
391397
check_prefix_and_exclusive(

testsuite/tests/checks/identifier_prefixes/prefix.ads

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ package Prefix is
2929
-- constant via renames
3030
Const3 : Type_Enum_1 renames Const_C1; -- FLAG
3131

32+
-- formal decls
33+
generic
34+
Gen_Param : Integer; -- NOFLAG
35+
Const_Gen_Param : Integer; -- FLAG
36+
package Gen_Pkg is
37+
end;
38+
3239
-- exception
3340
X_Exc_1 : exception;
3441
Exc_2 : exception; -- FLAG

testsuite/tests/checks/identifier_prefixes/test.out

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,39 +38,43 @@ prefix.ads:30:4: rule violation: Const3 does not start with constant prefix Cons
3838
30 | Const3 : Type_Enum_1 renames Const_C1; -- FLAG
3939
| ^^^^^^
4040

41-
prefix.ads:34:4: rule violation: Exc_2 does not start with exception prefix X_
42-
34 | Exc_2 : exception; -- FLAG
41+
prefix.ads:35:7: rule violation: Const_Gen_Param is not a constant but starts with Const_
42+
35 | Const_Gen_Param : Integer; -- FLAG
43+
| ^^^^^^^^^^^^^^^
44+
45+
prefix.ads:41:4: rule violation: Exc_2 does not start with exception prefix X_
46+
41 | Exc_2 : exception; -- FLAG
4347
| ^^^^^
4448

45-
prefix.ads:38:9: rule violation: Root2 does not start with derived prefix Root_
46-
38 | type Root2 is new Root; -- FLAG
49+
prefix.ads:45:9: rule violation: Root2 does not start with derived prefix Root_
50+
45 | type Root2 is new Root; -- FLAG
4751
| ^^^^^
4852

49-
prefix.ads:39:9: rule violation: Root_1 does not start with subtype prefix Type_
50-
39 | type Root_1 is new Integer; -- FLAG
53+
prefix.ads:46:9: rule violation: Root_1 does not start with subtype prefix Type_
54+
46 | type Root_1 is new Integer; -- FLAG
5155
| ^^^^^^
5256

53-
prefix.ads:45:9: rule violation: Root4 does not start with derived prefix Root_
54-
45 | type Root4 is new Type_Sub2; -- FLAG
57+
prefix.ads:52:9: rule violation: Root4 does not start with derived prefix Root_
58+
52 | type Root4 is new Type_Sub2; -- FLAG
5559
| ^^^^^
5660

57-
prefix.ads:52:14: rule violation: My_Task does not start with concurrent prefix Type_Conc_
58-
52 | task type My_Task is -- FLAG
61+
prefix.ads:59:14: rule violation: My_Task does not start with concurrent prefix Type_Conc_
62+
59 | task type My_Task is -- FLAG
5963
| ^^^^^^^
6064

61-
prefix.ads:60:19: rule violation: My_Protected does not start with concurrent prefix Type_Conc_
62-
60 | protected type My_Protected is -- FLAG
65+
prefix.ads:67:19: rule violation: My_Protected does not start with concurrent prefix Type_Conc_
66+
67 | protected type My_Protected is -- FLAG
6367
| ^^^^^^^^^^^^
6468

65-
prefix.ads:64:9: rule violation: Type_Conc_Rec is not a concurrent but starts with Type_Conc_
66-
64 | type Type_Conc_Rec is null record; -- FLAG
69+
prefix.ads:71:9: rule violation: Type_Conc_Rec is not a concurrent but starts with Type_Conc_
70+
71 | type Type_Conc_Rec is null record; -- FLAG
6771
| ^^^^^^^^^^^^^
6872

69-
prefix.ads:65:9: rule violation: Type_Conc_Der is not a concurrent but starts with Type_Conc_
70-
65 | type Type_Conc_Der is new Integer; -- FLAG
73+
prefix.ads:72:9: rule violation: Type_Conc_Der is not a concurrent but starts with Type_Conc_
74+
72 | type Type_Conc_Der is new Integer; -- FLAG
7175
| ^^^^^^^^^^^^^
7276

73-
prefix.ads:67:4: rule violation: Const_Or_Node is not a constant but starts with Const_
74-
67 | Const_Or_Node : Integer := 1; -- FLAG
77+
prefix.ads:74:4: rule violation: Const_Or_Node is not a constant but starts with Const_
78+
74 | Const_Or_Node : Integer := 1; -- FLAG
7579
| ^^^^^^^^^^^^^
7680

0 commit comments

Comments
 (0)