This patch removes spurious visibility errors from the instantiation of a generic package nested within another generic, when the inner package contains an expression function that is the completion of a visible function of that package, and the expression includes an object of a tagged type local to the generic.
No small example available. Tested on x86_64-pc-linux-gnu, committed on trunk 2017-09-29 Ed Schonberg <schonb...@adacore.com> * sem_ch6.adb (Analyze_Expression_Function): Do not emit freeze nodes for types in expression if the function is within a generic unit. * sem_res.adb (Resolve): In a generic context do not freeze an expression, unless it is an entity. This exception is solely for the purpose of detecting illegal uses of deferred constants in generic units. * sem_res.adb: Minor reformatting.
Index: sem_ch6.adb =================================================================== --- sem_ch6.adb (revision 253283) +++ sem_ch6.adb (working copy) @@ -568,8 +568,11 @@ -- Note that we cannot defer this freezing to the analysis of the -- expression itself, because a freeze node might appear in a nested -- scope, leading to an elaboration order issue in gigi. + -- As elsewhere, we do not emit freeze nodes within a generic unit. - Freeze_Expr_Types (Def_Id); + if not Inside_A_Generic then + Freeze_Expr_Types (Def_Id); + end if; -- For navigation purposes, indicate that the function is a body Index: sem_res.adb =================================================================== --- sem_res.adb (revision 253283) +++ sem_res.adb (working copy) @@ -3070,8 +3070,15 @@ -- Here we are resolving the corresponding expanded body, so we do -- need to perform normal freezing. - Freeze_Expression (N); + -- As elsewhere we do not emit freeze node within a generic. We make + -- an exception for entities that are expressions, only to detect + -- misuses of deferred constants and preserve the output of various + -- tests. + if not Inside_A_Generic or else Is_Entity_Name (N) then + Freeze_Expression (N); + end if; + -- Now we can do the expansion Expand (N);