+2019-07-04 Ed Schonberg <schonberg@adacore.com>
+
+ * sem_ch10.adb (Remove_Context_Clauses): Handle properly the
+ removal of a limited_with_clause which appears in the library
+ unit oF the main unit, when some other unit in the context has a
+ regular with_clause on the same unit, to prevent spurious
+ visibility errors in the subsequent analysis of pending instance
+ bodies.
+
2019-07-04 Hristian Kirtchev <kirtchev@adacore.com>
* sem_elab.adb: Add new type Elaboration_Phase_Status along with
begin
-- Ada 2005 (AI-50217): We remove the context clauses in two phases:
- -- limited-views first and regular-views later (to maintain the
- -- stack model).
+ -- limited-views first and regular-views later (to maintain the stack
+ -- model).
-- First Phase: Remove limited_with context clauses
Item := First (Context_Items (N));
while Present (Item) loop
- -- We are interested only in with clauses which got installed
- -- on entry.
+ -- We are interested only in with clauses that got installed on entry
if Nkind (Item) = N_With_Clause
and then Limited_Present (Item)
- and then Limited_View_Installed (Item)
then
- Remove_Limited_With_Clause (Item);
+ if Limited_View_Installed (Item) then
+ Remove_Limited_With_Clause (Item);
+
+ -- An unusual case: If the library unit of the Main_Unit has
+ -- a limited with_clause on some unit P and the context somewhere
+ -- includes a with_clause on P, P has been analyzed. The entity
+ -- for P is still visible, which in general is harmless because
+ -- this is the end of the compilation, but it can affect pending
+ -- instantiations that may have been generated elsewhere, so it
+ -- it is necessary to remove U from visibility so that inlining
+ -- and the analysis of instance bodies can proceed cleanly.
+
+ elsif Current_Sem_Unit = Main_Unit
+ and then Serious_Errors_Detected = 0
+ and then not Implicit_With (Item)
+ then
+ Set_Is_Immediately_Visible
+ (Defining_Entity (Unit (Library_Unit (Item))), False);
+ end if;
end if;
Next (Item);