Skip to content

Support for nested functions - seems to work, needs further investigation #164

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

Open
sonodtt opened this issue Mar 19, 2019 · 0 comments
Open

Comments

@sonodtt
Copy link
Contributor

sonodtt commented Mar 19, 2019

When implementing nested declares (#156), we found that nested functions largely appear to work out of the box.
Some further investigation and tests of edge cases should be the next step.

See the below example (which is now the test scenario for statement_new_block_N_Block_Statement)

#+BEGIN_SRC ada
function Statement_Block return Integer is
   Var1 : Integer :=1;
   Var2 : Integer;

    function Sum_Plus_Three(Left, Right : Integer) return Integer is
      Local1 : Integer;
   begin
      declare
         Local2 : Integer := 1;
      begin
         Local1 := Local2 + Var1 + 1;
         Pragma Assert (Local1=3);
      end;
   return (Left + Right + Local1);
   end Sum_Plus_Three;

 begin
   ----------------------------------------
   --  the below nested function call works, but is out of scope
   --  and nested functions are not yet fully supported / tested
   ----------------------------------------
   --  Var1 := Sum_Plus_Three(3,4);
   --  pragma Assert (Var1=10);
   ----------------------------------------

    declare
      Var3 : Integer :=2;
   begin
      Var2 := Var3;
      pragma Assert (Var2=2);
      declare
         Var4 : Integer := Var3;
      begin
         Var2 := Var4 + Var2;
         Pragma Assert (Var2=4);
      end;
   end;

    declare
      Var5 : Integer := 6;
   begin
      Var2 := Var5 + Var2;
   end;

    pragma Assert (Var2=10);
   return Var2;
end Statement_Block;

#+END_SRC
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

1 participant