===================================================================
@@ -1732,6 +1732,8 @@
Disc : Entity_Id)
is
Loc : constant Source_Ptr := Sloc (Expr);
+ I : Interp_Index;
+ It : Interp;
begin
-- An entity of a type with a reference aspect is overloaded with
@@ -1744,6 +1746,29 @@
Set_Etype (Expr, Etype (Entity (Expr)));
elsif Nkind (Expr) = N_Function_Call then
+
+ -- If the name of the indexing function is overloaded, locate the one
+ -- whose return type has an implicit dereference on the desired
+ -- discriminant, and set entity and type of function call.
+
+ if Is_Overloaded (Name (Expr)) then
+ Get_First_Interp (Name (Expr), I, It);
+
+ while Present (It.Nam) loop
+ if Ekind ((It.Typ)) = E_Record_Type
+ and then First_Entity ((It.Typ)) = Disc
+ then
+ Set_Entity (Name (Expr), It.Nam);
+ Set_Etype (Name (Expr), Etype (It.Nam));
+ exit;
+ end if;
+
+ Get_Next_Interp (I, It);
+ end loop;
+ end if;
+
+ -- Set type of call from resolved function name.
+
Set_Etype (Expr, Etype (Name (Expr)));
end if;
===================================================================
@@ -3073,6 +3073,7 @@
if not Is_Type (Nam) then
if Is_Entity_Name (Name (N)) then
Set_Entity (Name (N), Nam);
+ Set_Etype (Name (N), Etype (Nam));
elsif Nkind (Name (N)) = N_Selected_Component then
Set_Entity (Selector_Name (Name (N)), Nam);
@@ -7456,6 +7457,9 @@
end if;
else
+ -- If there are multiple indexing functions, build a function call
+ -- and analyze it for each of the possible interpretations.
+
Indexing :=
Make_Function_Call (Loc,
Name =>
@@ -7464,6 +7468,8 @@
Set_Parent (Indexing, Parent (N));
Set_Generalized_Indexing (N, Indexing);
+ Set_Etype (N, Any_Type);
+ Set_Etype (Name (Indexing), Any_Type);
declare
I : Interp_Index;
@@ -7473,21 +7479,24 @@
begin
Get_First_Interp (Func_Name, I, It);
Set_Etype (Indexing, Any_Type);
+
while Present (It.Nam) loop
Analyze_One_Call (Indexing, It.Nam, False, Success);
if Success then
- Set_Etype (Name (Indexing), It.Typ);
- Set_Entity (Name (Indexing), It.Nam);
- Set_Etype (N, Etype (Indexing));
- -- Add implicit dereference interpretation
+ -- Function in current interpretation is a valid candidate.
+ -- Its result type is also a potential type for the
+ -- original Indexed_Component node.
+ Add_One_Interp (Name (Indexing), It.Nam, It.Typ);
+ Add_One_Interp (N, It.Nam, It.Typ);
+
+ -- Add implicit dereference interpretation to original node
+
if Has_Discriminants (Etype (It.Nam)) then
Check_Implicit_Dereference (N, Etype (It.Nam));
end if;
-
- exit;
end if;
Get_Next_Interp (I, It);