Skip to content

Commit

Permalink
Test.Stub: Robustify calls to LAL API
Browse files Browse the repository at this point in the history
This change adds a fallback in case of property errors when determining
if a parameter type is definite or not. As we have a safe default, only
warn in such cases.
  • Loading branch information
leocreuse committed Mar 7, 2024
1 parent 5925945 commit af8109b
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/test-stub.adb
Original file line number Diff line number Diff line change
Expand Up @@ -2162,8 +2162,18 @@ package body Test.Stub is

function Can_Declare_Variable (Param_Type : Type_Expr) return Boolean is
Param_Type_Name : Libadalang.Analysis.Name;
Attr_Name : Identifier;
Attr_Name : Identifier;
Type_Decl : Base_Type_Decl;
begin
Type_Decl := Param_Type.P_Designated_Type_Decl;
if Type_Decl.Is_Null then
if not Quiet then
Report_Err
("Could not determine type referenced by "
& Param_Type.Image);
end if;
return False;
end if;

if Is_Only_Limited_Withed (Param_Type) then
return False;
Expand All @@ -2179,11 +2189,21 @@ package body Test.Stub is
end if;
end if;

return
Get_Declaration
(Param_Type.As_Subtype_Indication).P_Is_Definite_Subtype
(Param_Type);

return Type_Decl.P_Is_Definite_Subtype (Param_Type);
exception
when Ex : Property_Error =>
if not Verbose then
Trace
(Me,
"Could not determine if type " & Param_Type.Image
& " is definite");
else
Report_Err
("Could not determine if type " & Param_Type.Image
& " is definite, assuming it is not.");
end if;
Report_Ex (Ex);
return False;
end Can_Declare_Variable;

begin
Expand Down

0 comments on commit af8109b

Please sign in to comment.