or else
Nkind_In (D_Ityp, N_Object_Declaration,
N_Object_Renaming_Declaration,
+ N_Formal_Object_Declaration,
N_Formal_Type_Declaration,
N_Task_Type_Declaration,
N_Protected_Type_Declaration))
-- is already known to be compatible, and because this may be an
-- indexing of a call with default parameters.
- Formal : Entity_Id;
- Actual : Node_Id;
- Is_Indexed : Boolean := False;
- Subp_Type : constant Entity_Id := Etype (Nam);
- Norm_OK : Boolean;
+ Formal : Entity_Id;
+ Actual : Node_Id;
+ Is_Indexed : Boolean := False;
+ Is_Indirect : Boolean := False;
+ Subp_Type : constant Entity_Id := Etype (Nam);
+ Norm_OK : Boolean;
function Operator_Hidden_By (Fun : Entity_Id) return Boolean;
-- There may be a user-defined operator that hides the current
-- in prefix notation, so that the rebuilt parameter list has more than
-- one actual.
+ if not Is_Overloadable (Nam)
+ and then Ekind (Nam) /= E_Subprogram_Type
+ and then Ekind (Nam) /= E_Entry_Family
+ then
+ return;
+ end if;
+
if Present (Actuals)
and then
(Needs_No_Actuals (Nam)
-- The prefix can also be a parameterless function that returns an
-- access to subprogram, in which case this is an indirect call.
+ -- If this succeeds, an explicit dereference is added later on,
+ -- in Analyze_Call or Resolve_Call.
elsif Is_Access_Type (Subp_Type)
and then Ekind (Designated_Type (Subp_Type)) = E_Subprogram_Type
then
- Is_Indexed := Try_Indirect_Call (N, Nam, Subp_Type);
+ Is_Indirect := Try_Indirect_Call (N, Nam, Subp_Type);
end if;
end if;
return;
end if;
- Normalize_Actuals (N, Nam, (Report and not Is_Indexed), Norm_OK);
+ Normalize_Actuals
+ (N, Nam, (Report and not Is_Indexed and not Is_Indirect), Norm_OK);
if not Norm_OK then
+ -- If an indirect call is a possible interpretation, indicate
+ -- success to the caller.
+
+ if Is_Indirect then
+ Success := True;
+ return;
+
-- Mismatch in number or names of parameters
- if Debug_Flag_E then
+ elsif Debug_Flag_E then
Write_Str (" normalization fails in call ");
Write_Int (Int (N));
Write_Str (" with subprogram ");
Write_Eol;
end if;
- if Report and not Is_Indexed then
+ if Report and not Is_Indexed and not Is_Indirect then
-- Ada 2005 (AI-251): Complete the error notification
-- to help new Ada 2005 users
-- "return access T" case; check that the return statement also has
-- "access T", and that the subtypes statically match:
+ -- if this is an access to subprogram the signatures must match.
if R_Type_Is_Anon_Access then
if R_Stm_Type_Is_Anon_Access then
- if Base_Type (Designated_Type (R_Stm_Type)) /=
- Base_Type (Designated_Type (R_Type))
- or else not Subtypes_Statically_Match (R_Stm_Type, R_Type)
+ if
+ Ekind (Designated_Type (R_Stm_Type)) /= E_Subprogram_Type
then
- Error_Msg_N
- ("subtype must statically match function result subtype",
- Subtype_Mark (Subtype_Ind));
+ if Base_Type (Designated_Type (R_Stm_Type)) /=
+ Base_Type (Designated_Type (R_Type))
+ or else not Subtypes_Statically_Match (R_Stm_Type, R_Type)
+ then
+ Error_Msg_N
+ ("subtype must statically match function result subtype",
+ Subtype_Mark (Subtype_Ind));
+ end if;
+
+ else
+ -- For two anonymous access to subprogram types, the
+ -- types themselves must be type conformant.
+
+ if not Conforming_Types
+ (R_Stm_Type, R_Type, Fully_Conformant)
+ then
+ Error_Msg_N
+ ("subtype must statically match function result subtype",
+ Subtype_Ind);
+ end if;
end if;
else
end loop;
end if;
+ if Ekind (Etype (Nam)) = E_Access_Subprogram_Type
+ and then Ekind (Typ) /= E_Access_Subprogram_Type
+ and then Nkind (Subp) /= N_Explicit_Dereference
+ and then Present (Parameter_Associations (N))
+ then
+ -- The prefix is a parameterless function call that returns an
+ -- access to subprogram. If parameters are present in the current
+ -- call add an explicit dereference.
+
+ -- The dereference is added either in Analyze_Call or here. Should
+ -- be consolidated ???
+
+ Set_Is_Overloaded (Subp, False);
+ Set_Etype (Subp, Etype (Nam));
+ Insert_Explicit_Dereference (Subp);
+ Nam := Designated_Type (Etype (Nam));
+ Resolve (Subp, Nam);
+ end if;
+
-- Check that a call to Current_Task does not occur in an entry body
if Is_RTE (Nam, RE_Current_Task) then
-- Access to subprogram types. If the operand is an access parameter,
-- the type has a deeper accessibility that any master, and cannot
- -- be assigned.
+ -- be assigned. We must make an exception if the conversion is part
+ -- of an assignment and the target is the return object of an extended
+ -- return statement, because in that case the accessibility check
+ -- takes place after the return.
elsif (Ekind (Target_Type) = E_Access_Subprogram_Type
or else
if Ekind (Base_Type (Opnd_Type)) = E_Anonymous_Access_Subprogram_Type
and then Is_Entity_Name (Operand)
and then Ekind (Entity (Operand)) = E_In_Parameter
+ and then
+ (Nkind (Parent (N)) /= N_Assignment_Statement
+ or else not Is_Entity_Name (Name (Parent (N)))
+ or else not Is_Return_Object (Entity (Name (Parent (N)))))
then
Error_Msg_N
("illegal attempt to store anonymous access to subprogram",