Skip to content

Commit 68f0c82

Browse files
committed
Merge branch 'topic/453' into 'master'
Fix use_memberships rule to avoid calling properties with null nodes Closes #453 See merge request eng/libadalang/langkit-query-language!419
2 parents 090fb4b + a97f6a5 commit 68f0c82

File tree

3 files changed

+38
-20
lines changed

3 files changed

+38
-20
lines changed

lkql_checker/share/lkql/use_memberships.lkql

+3-1
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,6 @@ fun use_memberships(node, short_circuit = false) =
120120
) when stdlib.is_predefined_op(op)
121121

122122
# Find a first variable used as LHS (id) and pass it to check_expr
123-
and check_expr(node, get_first_id(node), short_circuit)
123+
and if not get_first_id(node) is null
124+
then check_expr(node, get_first_id(node), short_circuit)
125+
else false

testsuite/tests/checks/use_memberships/member.adb

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
procedure Member (A, B : Integer) is
22
Bool : Boolean;
33
subtype S is Integer range 1 .. B;
4+
type E is (X, Y, Z);
5+
6+
function Func (A, B, C : Integer) return E is (X);
47
begin
58
if A = 0 -- FLAG
69
or A in Natural
@@ -40,4 +43,9 @@ begin
4043
Bool := A >= 1 and A <= B; -- FLAG
4144
Bool := A = 100 or A in S; -- FLAG
4245
Bool := A = 100 or A in 1 .. B; -- FLAG
46+
47+
if Func (1, 2, 3) in X or -- NOFLAG
48+
Func (3, 4, 5) in Y then
49+
null;
50+
end if;
4351
end Member;

testsuite/tests/checks/use_memberships/test.out

+27-19
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
member.adb:5:7: rule violation: expression may be replaced by a membership test
2-
5 | if A = 0 -- FLAG
3-
| _______^
4-
||
5-
|| ~~~ 2 other lines ~~~
6-
||
7-
8 || or (A >= 3 and A <= 5)
8-
||___________________________^
1+
member.adb:8:7: rule violation: expression may be replaced by a membership test
2+
8 | if A = 0 -- FLAG
3+
| _______^
4+
||
5+
|| ~~~ 2 other lines ~~~
6+
||
7+
11 || or (A >= 3 and A <= 5)
8+
||___________________________^
99

10-
member.adb:13:7: rule violation: expression may be replaced by a membership test
11-
13 | if A = 0 -- FLAG if short_circuit
10+
member.adb:16:7: rule violation: expression may be replaced by a membership test
11+
16 | if A = 0 -- FLAG if short_circuit
1212
| _______^
13-
14 || or else (A >= 3 and A <= 5)
13+
17 || or else (A >= 3 and A <= 5)
1414
||________________________________^
1515

16-
member.adb:39:12: rule violation: expression may be replaced by a membership test
17-
39 | Bool := A = B or (A >= 1 and A <= B); -- FLAG
16+
member.adb:42:12: rule violation: expression may be replaced by a membership test
17+
42 | Bool := A = B or (A >= 1 and A <= B); -- FLAG
1818
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1919

20-
member.adb:40:12: rule violation: expression may be replaced by a membership test
21-
40 | Bool := A >= 1 and A <= B; -- FLAG
20+
member.adb:43:12: rule violation: expression may be replaced by a membership test
21+
43 | Bool := A >= 1 and A <= B; -- FLAG
2222
| ^^^^^^^^^^^^^^^^^
2323

24-
member.adb:41:12: rule violation: expression may be replaced by a membership test
25-
41 | Bool := A = 100 or A in S; -- FLAG
24+
member.adb:44:12: rule violation: expression may be replaced by a membership test
25+
44 | Bool := A = 100 or A in S; -- FLAG
2626
| ^^^^^^^^^^^^^^^^^
2727

28-
member.adb:42:12: rule violation: expression may be replaced by a membership test
29-
42 | Bool := A = 100 or A in 1 .. B; -- FLAG
28+
member.adb:45:12: rule violation: expression may be replaced by a membership test
29+
45 | Bool := A = 100 or A in 1 .. B; -- FLAG
3030
| ^^^^^^^^^^^^^^^^^^^^^^
3131

3232
Patched "member.adb":
@@ -35,6 +35,9 @@ Patched "member.adb":
3535
procedure Member (A, B : Integer) is
3636
Bool : Boolean;
3737
subtype S is Integer range 1 .. B;
38+
type E is (X, Y, Z);
39+
40+
function Func (A, B, C : Integer) return E is (X);
3841
begin
3942
if A in 0 -- FLAG
4043
|Natural
@@ -72,5 +75,10 @@ begin
7275
Bool := A in 1 ..B; -- FLAG
7376
Bool := A in 100 |S; -- FLAG
7477
Bool := A in 100 |1 .. B; -- FLAG
78+
79+
if Func (1, 2, 3) in X or -- NOFLAG
80+
Func (3, 4, 5) in Y then
81+
null;
82+
end if;
7583
end Member;
7684

0 commit comments

Comments
 (0)