diff --git a/ada/ast.py b/ada/ast.py index c4bd2fb86..751e27f91 100644 --- a/ada/ast.py +++ b/ada/ast.py @@ -8509,7 +8509,9 @@ def iterable_cursor_type(): If Self is a type that is iterable (i.e.: it has the Iterable aspect defined), return the type of the cursor in use by this iterable type. """ - return Entity.get_aspect_spec_expr('Iterable').then( + return Entity.get_aspect( + 'Iterable', previous_parts_only=True + ).value.then( lambda it: it.cast(T.Aggregate).assocs.unpacked_params.find( lambda sa: sa.name.name_is('First') ).assoc.expr.cast_or_raise(T.Name).referenced_decl.expr_type diff --git a/testsuite/tests/name_resolution/iterable_aspect/private_view.adb b/testsuite/tests/name_resolution/iterable_aspect/private_view.adb new file mode 100644 index 000000000..7897fd57c --- /dev/null +++ b/testsuite/tests/name_resolution/iterable_aspect/private_view.adb @@ -0,0 +1,53 @@ +procedure Private_View is + package P is + type Sequence is private with + Iterable => (First => Iter_First, + Has_Element => Iter_Has_Element, + Next => Iter_Next); + + function Iter_First (Container : Sequence) return Integer; + function Iter_Has_Element + (Container : Sequence; + Position : Integer) return Boolean; + function Iter_Next + (Container : Sequence; + Position : Integer) return Integer; + private + + type Sequence is record + Content : String (1 .. 10); + end record; + + function Iter_First (Container : Sequence) return Integer is + (Container.Content'First); + function Iter_Has_Element + (Container : Sequence; + Position : Integer) return Boolean is + (Position < Container.Content'Last); + function Iter_Next + (Container : Sequence; + Position : Integer) return Integer is (Position + 1); + end P; + + package body P is + function Ident (I : Integer) return Boolean is (True); + + -- Below, Sequence refers to the private view of Sequence, which has no + -- aspect Iterable. `p_iterable_cursor_type` should also look for the + -- Iterable aspect on the public part too. + function "<" (Left : Sequence; Right : Sequence) return Boolean is + (for all N in Left => Ident (N)); + pragma Test_Statement; + + type New_Sequence is new Sequence; + + -- Below, New_Sequence refers to the type declared above, inheriting the + -- Iterable aspect from Sequence. `p_iterable_cursor_type` should also + -- look for the Iterable aspect on the parent types. + function "<" (Left : New_Sequence; Right : New_Sequence) return Boolean + is (for all N in Left => Ident (N)); + pragma Test_Statement; + end P; +begin + null; +end Private_View; diff --git a/testsuite/tests/name_resolution/iterable_aspect/test.out b/testsuite/tests/name_resolution/iterable_aspect/test.out index 6e9562cfb..62f9d0a55 100644 --- a/testsuite/tests/name_resolution/iterable_aspect/test.out +++ b/testsuite/tests/name_resolution/iterable_aspect/test.out @@ -154,4 +154,52 @@ Expr: expected type: None +Analyzing private_view.adb +########################## + +Resolving xrefs for node +*************************************************************************** + +Expr: + type: + expected type: +Expr: + type: + expected type: +Expr: + references: + type: + expected type: +Expr: + references: + type: + expected type: None +Expr: + references: + type: + expected type: + +Resolving xrefs for node +*************************************************************************** + +Expr: + type: + expected type: +Expr: + type: + expected type: +Expr: + references: + type: + expected type: +Expr: + references: + type: + expected type: None +Expr: + references: + type: + expected type: + + Done. diff --git a/testsuite/tests/name_resolution/iterable_aspect/test.yaml b/testsuite/tests/name_resolution/iterable_aspect/test.yaml index 173e325ff..326aa65d4 100644 --- a/testsuite/tests/name_resolution/iterable_aspect/test.yaml +++ b/testsuite/tests/name_resolution/iterable_aspect/test.yaml @@ -1,2 +1,2 @@ driver: name-resolution -input_sources: [test.adb] +input_sources: [test.adb, private_view.adb]