Skip to content

Commit 1332076

Browse files
committed
Merge branch 'topic/523' into 'master'
overriding_indicators: fix detection of late primtives Closes #523 See merge request eng/libadalang/langkit-query-language!510
2 parents 85f111e + 412dbc9 commit 1332076

File tree

5 files changed

+62
-2
lines changed

5 files changed

+62
-2
lines changed

lkql_checker/share/lkql/overriding_indicators.lkql

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,18 @@ fun is_overriding_subprogram(node) =
5050
p_primitive_subp_first_type(): t@TypeDecl(
5151
p_base_type(): bt@TypeDecl(
5252
p_get_primitives(): primitives@(not null)
53-
when stdlib.any([p for p in primitives if match_signature(node, p, t, bt)])
53+
when stdlib.any(
54+
[p for p in primitives
55+
# The primitive should match it's ancestor counterpart
56+
if match_signature(node, p, t, bt)
57+
# And, it should be inherited to be overrode (i.e.,
58+
# we can't override late primitives).
59+
and stdlib.any(
60+
[i for i in t.p_get_primitives(only_inherited=true)
61+
if match_signature(i, p, bt, bt)]
62+
)
63+
]
64+
)
5465
)
5566
)
5667
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package body Late is
2+
function Prim (Arg: T_Ancestor) return Float is
3+
begin
4+
return 0.1;
5+
end Prim;
6+
7+
function Prim (Arg: T_Descendant) return Float is -- FLAG
8+
begin
9+
return 0.2;
10+
end Prim;
11+
12+
13+
function Late_Prim (Arg: T_Ancestor) return Float is
14+
begin
15+
return 0.1;
16+
end Late_Prim;
17+
18+
function Late_Prim (Arg: T_Descendant) return Float is -- NOFLAG
19+
begin
20+
return 0.2;
21+
end Late_Prim;
22+
end Late;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package Late is
2+
type T_Ancestor is null record;
3+
4+
function Prim (Arg: T_Ancestor) return Float;
5+
6+
type T_Descendant is new T_Ancestor;
7+
8+
-- "Late" primitive of T_Ancestor. Can't be inherited by types declared
9+
-- before in the source Code.
10+
function Late_Prim (Arg: T_Ancestor) return Float;
11+
12+
-- The following operation cannot override the primive of T_Ancestor because
13+
-- the latter is not inherited by T_Descendant since the primitive of
14+
-- T_Ancestor has been declared *after* the declaration of T_Descendant.
15+
function Late_Prim (Arg: T_Descendant) return Float; -- NOFLAG
16+
17+
-- The following operation override the primitive of T_Ancestor
18+
function Prim (Arg: T_Descendant) return Float; -- FLAG
19+
end Late;

testsuite/tests/checks/overriding_indicators/test.out

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,11 @@ test-prim3.adb:2:11: rule violation: missing overriding indicator
4646
2 | procedure Prim3 (Self : T6; Other : Integer) is -- FLAG
4747
| ^^^^^
4848

49+
late.ads:18:13: rule violation: missing overriding indicator
50+
18 | function Prim (Arg: T_Descendant) return Float; -- FLAG
51+
| ^^^^
52+
53+
late.adb:7:13: rule violation: missing overriding indicator
54+
7 | function Prim (Arg: T_Descendant) return Float is -- FLAG
55+
| ^^^^
56+
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
driver: 'checker'
22
rule_name: overriding_indicators
3-
input_sources: ['test.ads', 'test.adb', 'test-prim3.adb']
3+
input_sources: ['test.ads', 'test.adb', 'test-prim3.adb', 'late.ads', 'late.adb']

0 commit comments

Comments
 (0)