AdaCore/libadalang

Python API tutorial fails with "dereferencing a null access"

jgueytat opened this issue · 2 comments

libadalang_PythonTutorial

While following the Python API Tutorial I get an excpetion.

PS C:\Users\gueytaj> gnatls.exe --version
GNATLS Pro 21.2 (20210531-93)
Copyright (C) 1992-2021, Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
See your AdaCore support agreement for details of warranty and support.
If you do not have a current support agreement, then there is absolutely
no warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.

If I replace LAL by Libadalang.Analysis in the adb file I don't get the exception.

== main.adb ==
Line 35: 'Context : constant Libadalang.Analysis.Analysis_Context := Libadalang.Analysis.Create_Context;'    
Line 40: 'Filename : constant String := Ada.Command_Line.Argument (I);' type is: 'type String is array (Positive range <>) of Character;'
Line 41: 'Unit     : constant Libadalang.Analysis.Analysis_Unit :=\r\n            Context.Get_From_File (Filename);'

package LAL renames Libadalang.Analysis; seems to be problematic for node.f_type_expr.p_designated_type_decl.

Hi,

I think this is because you are running the python script without a project file and thus Libadalang cannot find the dependencies of your ada file (Libadalang in this case).
Try adding:

with "libadalang";
project Prj is
end Prj;

And then running your script again with:

python main.py -P prj.gpr my_ada_file.adb

This should work if libadalang.gpr is in your GPR_PROJECT_PATH

I'll close this issue, feel free to reopen it you're still having issues!

Romain