Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property error when loading a P_Body_Part for a Generic_Subp_Decl #684

Closed
faedia opened this issue Feb 4, 2021 · 2 comments
Closed

Property error when loading a P_Body_Part for a Generic_Subp_Decl #684

faedia opened this issue Feb 4, 2021 · 2 comments
Assignees

Comments

@faedia
Copy link

faedia commented Feb 4, 2021

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

@faedia faedia changed the title Property error when loading a P_Body_Part Generic_Subp_Decl Property error when loading a P_Body_Part for a Generic_Subp_Decl Feb 4, 2021
@Roldak
Copy link
Contributor

Roldak commented Feb 5, 2021

Hello Steven,

Thanks for reporting this issue, I confirm I can reproduce locally.

Fortunately, we have a big patch coming up to Libadalang that seems to make this issue disappear. However this patch won't be merged on our master branch before a few weeks. I hope that's okay for you to wait a little bit for this issue to be fixed!

Best regards,

Romain

@Roldak Roldak self-assigned this Feb 5, 2021
@Roldak
Copy link
Contributor

Roldak commented Feb 7, 2022

Hello Steven,

I forgot to close this issue in the end, so I just double checked and I get no property error running your reproducer. I think it's been resolved since we merged the patch I mentioned in my last message.

Closing this!

Best regards,

Romain

@Roldak Roldak closed this as completed Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants