Skip to content

Property error when loading a P_Body_Part for a Generic_Subp_Decl #684

Closed
@faedia

Description

@faedia

This appears to occur because a with generic package is instantiated inside of the generic subprogram, and the generic package is width'd from another file that libadalang cannot find.

with pkg;

package body test_pkg is

   generic
      type t_type;
   package g_p_decl is
      function is_true (x : t_type) return Boolean (True);
   end g_p_decl;


   -- Fine because the generic package is in scope
   function g_foo_1 (x : t_type) return Boolean
   is
      package g_p_inst is new g_p_decl (t_type);
      use g_p_inst;
   begin
      return is_true (x);
   end g_foo;

   -- Error because can't find generic package
   function g_foo_2 (x : t_type) return Boolean
   is
      package g_p_inst is new pkg.g_p_decl (t_type);
      use g_p_inst;
   begin
      return is_true (x);
   end g_foo;

end test_pkg;

The erroneous subprogram is g_foo_2 because it uses g_p_decl from pkg and not from the local unit.

The following program demonstrates the error by iterating over all Ada_Generic_Subp_Decl and then trying to access the P_Body_Part of the generic.

with Libadalang.Analysis;
with Libadalang.Common;
with Libadalang.Iterators;
procedure Main is
   package LAL renames Libadalang.Analysis;
   package LAL_iter renames Libadalang.Iterators;
   package LAL_common renames Libadalang.Common;
   context : LAL.Analysis_Context := LAL.Create_Context;
   unit : LAL.Analysis_Unit := context.Get_From_File ("test_pkg.ads");
   pred : LAL_iter.Ada_Node_Predicate := LAL_iter.Kind_Is (LAL_common.Ada_Generic_Subp_Decl);
   iter : LAL_iter.Traverse_Iterator'Class := LAL_iter.Find (unit.Root, pred);
   Node : LAL.Ada_Node;
begin
   while iter.Next (Node) loop
      Node.Print;
      declare
         s_body : LAL.Ada_Node := Node.As_Generic_Subp_Decl.P_Body_Part.As_Ada_Node;
      begin
         s_body.Print;
      end;
   end loop;
end Main;

I'm not sure if this is expected behaviour, I would have expected it to be able to give me the body of the subprogram but have incomplete semantic analysis of the subprogram.

Here is a full reproducer for the issue, run the program in the test directory:
p_body_part_reproducer.zip

Thank you,
Steven

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions