From c0e938d0cdbc3ae9b202e855d9f7ccea96138344 Mon Sep 17 00:00:00 2001 From: Arnaud Charlet Date: Tue, 2 May 2017 10:32:34 +0200 Subject: [multiple changes] 2017-05-02 Hristian Kirtchev * exp_attr.adb: Minor reformatting. 2017-05-02 Ed Schonberg * sem_ch4.adb (Analyze_Selected_Component): Improve error detection for illegal references to private components or operations of a protected type in the body of the type. From-SVN: r247469 --- gcc/ada/sem_ch4.adb | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'gcc/ada/sem_ch4.adb') diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb index 4f2c1fd..12f930d 100644 --- a/gcc/ada/sem_ch4.adb +++ b/gcc/ada/sem_ch4.adb @@ -4311,6 +4311,7 @@ package body Sem_Ch4 is Act_Decl : Node_Id; Comp : Entity_Id; Has_Candidate : Boolean := False; + Hidden_Comp : Entity_Id; In_Scope : Boolean; Is_Private_Op : Boolean; Parent_N : Node_Id; @@ -4850,6 +4851,7 @@ package body Sem_Ch4 is -- can only be a direct name or an expanded name. Set_Etype (Sel, Any_Type); + Hidden_Comp := Empty; In_Scope := In_Open_Scopes (Prefix_Type); Is_Private_Op := False; @@ -4900,6 +4902,10 @@ package body Sem_Ch4 is Has_Candidate := True; else + if Ekind (Comp) = E_Component then + Hidden_Comp := Comp; + end if; + goto Next_Comp; end if; @@ -4921,6 +4927,20 @@ package body Sem_Ch4 is end if; <> + if Comp = First_Private_Entity (Type_To_Use) then + if Etype (Sel) /= Any_Type then + + -- We have a candiate. + exit; + + else + -- Indicate that subsequent operations are private, + -- for better error reporting. + + Is_Private_Op := True; + end if; + end if; + Next_Entity (Comp); exit when not In_Scope and then @@ -4968,11 +4988,20 @@ package body Sem_Ch4 is elsif In_Scope and then Is_Object_Reference (Original_Node (Prefix (N))) + and then Comes_From_Source (N) and then Is_Private_Op then - Error_Msg_NE - ("invalid reference to private operation of some object of " - & "type &", N, Type_To_Use); + if Present (Hidden_Comp) then + Error_Msg_NE + ("invalid reference to private component of object " + & "of type &", N, Type_To_Use); + + else + Error_Msg_NE + ("invalid reference to private operation of some object of " + & "type &", N, Type_To_Use); + end if; + Set_Entity (Sel, Any_Id); Set_Etype (Sel, Any_Type); return; -- cgit v1.1