Skip to content

Commit

Permalink
Merge branch 'topic/1354' into 'master'
Browse files Browse the repository at this point in the history
Fix p_body_part_for_decl for when body part is in separate unit

Closes #1354

See merge request eng/libadalang/libadalang!1610
  • Loading branch information
thvnx committed Apr 8, 2024
2 parents 6e28b8f + aa78c77 commit ad015e3
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 16 deletions.
31 changes: 15 additions & 16 deletions ada/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -10859,24 +10859,23 @@ def next_part_for_decl():
Not(default_next_part.is_null),
default_next_part,

# Self is declared in a private part
decl_scope.is_a(T.PrivatePart),
parent_decl.next_part_for_decl.then(
lambda np: Entity.get_body_in_env(np.children_env)
decl_scope.is_a(T.PrivatePart, T.PublicPart),
Let(
lambda other_part=If(
decl_scope.is_a(T.PrivatePart),
parent_decl.next_part_for_decl,
parent_decl.decl_private_part
):
# Search in other part
other_part.then(
lambda op: Entity.get_body_in_env(op.children_env)
)
# If not found, search in body
._or(parent_decl.body_part_for_decl.then(
lambda np: Entity.get_body_in_env(np.children_env)
))
),

# Self is declared in a public part
decl_scope.is_a(T.PublicPart),

# Search in private part
parent_decl.decl_private_part.then(
lambda dpp: Entity.get_body_in_env(dpp.children_env),
)
# If not found, search in body
._or(parent_decl.body_part_for_decl.then(
lambda np: Entity.get_body_in_env(np.children_env)
)),

# No declarative scope: Bail out!
decl_scope.is_null, No(T.Body.entity),

Expand Down
13 changes: 13 additions & 0 deletions testsuite/tests/properties/body_part_for_decl_separate/a.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
procedure A is
package P is
procedure Bar;
--% node.p_body_part_for_decl()
private
procedure Foo;
--% node.p_body_part_for_decl()
end P;

package body P is separate;
begin
null;
end A;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
separate(A)
package body P is
procedure Bar is null;
procedure Foo is null;
end P;
11 changes: 11 additions & 0 deletions testsuite/tests/properties/body_part_for_decl_separate/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Working on node <SubpDecl ["Bar"] a.adb:3:7-3:21>
=================================================

Eval 'node.p_body_part_for_decl()'
Result: <NullSubpDecl ["Bar"] a~p.adb:3:4-3:26>

Working on node <SubpDecl ["Foo"] a.adb:6:7-6:21>
=================================================

Eval 'node.p_body_part_for_decl()'
Result: <NullSubpDecl ["Foo"] a~p.adb:4:4-4:26>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
driver: inline-playground
input_sources: [a.adb]

0 comments on commit ad015e3

Please sign in to comment.