File tree Expand file tree Collapse file tree 4 files changed +34
-12
lines changed
testsuite/tests/checks/controlled_type_declarations Expand file tree Collapse file tree 4 files changed +34
-12
lines changed Original file line number Diff line number Diff line change 8
8
# declared in `Ada.Finalization' but has a controlled component is not
9
9
# checked.
10
10
11
+ import stdlib
12
+
11
13
fun canonical_fully_qualified_name(t) =
12
14
t.f_name?.p_basic_decl()?.p_canonical_fully_qualified_name()
13
15
14
- selector complete_super_types
15
- | b@BaseTypeDecl when b.p_is_private() =>
16
- rec(*this.p_next_part()?.p_base_types?())
17
- | BaseTypeDecl =>
18
- rec(*this.p_base_types())
19
- | * => ()
20
-
21
16
@check(message="declaration of controlled type", category="Feature")
22
17
fun controlled_type_declarations(node) =
23
- node is BaseTypeDecl (
24
- any complete_super_types: b
18
+ node is TypeDecl (
19
+ any stdlib. complete_super_types: b
25
20
when canonical_fully_qualified_name(b) == "ada.finalization.controlled"
26
21
)
Original file line number Diff line number Diff line change 5
5
|" library.
6
6
7
7
selector super_types
8
- |" Yields the chain of super types for the given type
8
+ |" Yields the chain of super types of the given type, as viewed from that
9
+ |" type. Hence, for a type T which public view derives from a type A but
10
+ |" private view derives from a type B (which itself derives from A),
11
+ |" invoking this selector on the public view of T will yield A.
9
12
| BaseTypeDecl => rec(*this.p_base_types())
10
13
| * => ()
11
14
15
+ selector complete_super_types
16
+ |" Yields the chain of super types of the given type in their most complete
17
+ |" view. Hence, for a type T which public view derives from a type A but
18
+ |" private view derives from a type B (which itself derives from A),
19
+ |" invoking this selector on the public view of T will yield B and then A.
20
+ | b@BaseTypeDecl when b.p_is_private() => {
21
+ # We go through `p_base_subtype` to correctly handle SubtypeDecl nodes:
22
+ # while they themselves don't have a next part, their base type may.
23
+ val np = this.p_base_subtype().p_next_part();
24
+ val typ = if np == null then this else np;
25
+ rec(*typ.p_base_types())
26
+ }
27
+ | BaseTypeDecl =>
28
+ rec(*this.p_base_types())
29
+ | * => ()
30
+
12
31
selector semantic_parent
13
32
|" Return all semantic parent nodes starting from a given node.
14
33
| null => ()
Original file line number Diff line number Diff line change 1
1
with Ada.Finalization ;
2
2
package Foo is
3
3
type Resource is new Ada.Finalization.Controlled with private ; -- FLAG
4
+
5
+ subtype Sub_Resource is Resource; -- NOFLAG
6
+
7
+ type New_Resource is new Sub_Resource; -- FLAG
4
8
private
5
9
type Resource is new Ada.Finalization.Controlled with null record ; -- FLAG
6
10
type Ressource_Array is new Array (Positive range <>)
Original file line number Diff line number Diff line change @@ -2,7 +2,11 @@ controlled_type_declarations.ads:3:9: rule violation: declaration of controlled
2
2
3 | type Resource is new Ada.Finalization.Controlled with private; -- FLAG
3
3
| ^^^^^^^^
4
4
5
- controlled_type_declarations.ads:5:9: rule violation: declaration of controlled type
6
- 5 | type Resource is new Ada.Finalization.Controlled with null record; -- FLAG
5
+ controlled_type_declarations.ads:7:9: rule violation: declaration of controlled type
6
+ 7 | type New_Resource is new Sub_Resource; -- FLAG
7
+ | ^^^^^^^^^^^^
8
+
9
+ controlled_type_declarations.ads:9:9: rule violation: declaration of controlled type
10
+ 9 | type Resource is new Ada.Finalization.Controlled with null record; -- FLAG
7
11
| ^^^^^^^^
8
12
You can’t perform that action at this time.
0 commit comments