This patch fixes a spurious conformance error on the occurrence of the discriminant of a protected type in the expression for an aspect of the type, when the type and its body appear within a subprogram body. The check that the expression has the same visbility at the freeze point of the type and at the end of the current declarative list may have to examine two different entities which result from analysis and expansion steps at the freeze point and after analysis of the body and construction of the corresponding protected subprograms.
The following must compile quietly: --- with System; procedure Aspect_Bug is subtype Data is Integer range 1 .. 10; protected type Event (Ceiling : System.Priority) with Priority => Ceiling -- Ceiling priority defined for each object is entry Wait (D : out Data); procedure Signal (D : in Data); private Current : Data; -- Event data declaration Signalled : Boolean := False; end Event; protected body Event is entry Wait (D : out Data) when Signalled is begin D := Current; Signalled := False; end Wait; procedure Signal (D : in Data) is begin Current := D; Signalled := True; end Signal; end Event; It : Event (15); begin null; end; Tested on x86_64-pc-linux-gnu, committed on trunk 2017-05-02 Ed Schonberg <schonb...@adacore.com> * sem_ch6.adb (Fully_Conformant_Expressions): Two entity references are fully conformant if they are both expansions of the discriminant of a protected type, within one of the protected operations. One occurrence may be expanded into a constant declaration while the other is an input parameter to the corresponding generated subprogram.
Index: sem_ch6.adb =================================================================== --- sem_ch6.adb (revision 247461) +++ sem_ch6.adb (working copy) @@ -8770,6 +8770,16 @@ and then Ekind (Entity (E1)) = E_Discriminant and then Ekind (Entity (E2)) = E_In_Parameter) + -- The discriminant of a protected type is transformed into + -- a local constant and then into a parameter of a protected + -- operation. + + or else (Ekind (Entity (E1)) = E_Constant + and then Ekind (Entity (E2)) = E_In_Parameter + and then Present (Discriminal_Link (Entity (E1))) + and then Discriminal_Link (Entity (E1)) = + Discriminal_Link (Entity (E2))) + -- AI12-050: The loop variables of quantified expressions -- match if they have the same identifier, even though they -- are different entities.