[Ada] Fix bogus visibility error with partially parameterized formal package
commitca3e565395b8e49f90482409c7cb2da5fccb5b26
authorEric Botcazou <ebotcazou@adacore.com>
Thu, 17 Mar 2022 18:05:10 +0000 (17 19:05 +0100)
committerPierre-Marie de Rodat <derodat@adacore.com>
Tue, 17 May 2022 08:25:45 +0000 (17 08:25 +0000)
tree4134273059a469c41acd08bcd894eb1f69880f64
parent27b2b83bd7c1a9dfdba4ef27ea120ae5e1ead0b0
[Ada] Fix bogus visibility error with partially parameterized formal package

The problem comes from the special instantiation (abbreviated instantiation
in GNAT parlance) done to check conformance between a formal package and its
corresponding actual in a generic instantiation: the compiler instantiates
the formal package, in the context of the generic instantiation, so that it
can check the conformance of the actual with the result.

More precisely, it occurs with formal packages that are only partially
parameterized, i.e. that have at least one parameter association and an
(others => <>) choice. In this case, RM 12.7(10/2) says that the visible
part of the formal package contains a copy of the formal parameters that
are not explicitly associated.

The analysis of these copies for the abbreviated instantiation is not done
in the correct context when the generic unit is a child generic unit.

gcc/ada/

* sem_ch12.ads (Is_Abbreviated_Instance): Declare.
* sem_ch12.adb (Check_Abbreviated_Instance): Declare.
(Requires_Conformance_Checking): Declare.
(Analyze_Association.Process_Default): Fix subtype of parameter.
(Analyze_Formal_Object_Declaration): Check whether it is in the
visible part of abbreviated instance.
(Analyze_Formal_Subprogram_Declaration): Likewise.
(Analyze_Formal_Type_Declaration): Likewise.
(Analyze_Package_Instantiation): Do not check for a generic child
unit in the case of an abbreviated instance.
(Check_Abbreviated_Instance): New procedure.
(Check_Formal_Packages): Tidy up.
(Copy_Generic_Elist): Fix comment.
(Instantiate_Formal_Package): Tidy up.  If the generic unit is a
child unit, copy the qualified name onto the abbreviated instance.
(Is_Abbreviated_Instance): New function.
(Collect_Previous_Instances): Call Is_Abbreviated_Instance.
(Requires_Conformance_Checking): New function.
* sem_ch7.adb (Analyze_Package_Specification): Do not install the
private declarations of the parent for an abbreviated instance.
gcc/ada/sem_ch12.adb
gcc/ada/sem_ch12.ads
gcc/ada/sem_ch7.adb