https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64869
--- Comment #5 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
The problem is in Freeze.Freeze_Before:
-- If the entity is a type declared in an inner package, it may be
-- frozen by an outer declaration before the package itself is
-- frozen. Install the package scope to analyze the freeze nodes,
-- which may include generated subprograms such as predicate
-- functions, etc.
if Is_Type (T) and then From_Nested_Package (T) then
Push_Scope (Pack);
Install_Visible_Declarations (Pack);
Install_Private_Declarations (Pack);
Insert_Actions (N, Freeze_Nodes);
End_Package_Scope (Pack);
else
Insert_Actions (N, Freeze_Nodes);
end if;
where End_Package_Scope resets the visibility of the type T.