diff mbox series

[Ada] Error in instance on incomplete actual passed to formal incomplete type

Message ID 20210617143311.GA9993@adacore.com
State New
Headers show
Series [Ada] Error in instance on incomplete actual passed to formal incomplete type | expand

Commit Message

Pierre-Marie de Rodat June 17, 2021, 2:33 p.m. UTC
The compiler wrongly issues an error on a generic instantiation when an
incomplete view of a type that is completed before the instantiation is
given as an actual for a formal incomplete type. We now check whether
the full view of the actual incomplete type is present at that point,
and associate the full view with the actual rather than the incomplete
view.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* sem_ch12.adb (Instantiate_Type): If the actual type for an
	incomplete formal type is also incomplete, but has a Full_View,
	use the Full_View of the actual type rather than the incomplete
	view.
diff mbox series

Patch

diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -14022,9 +14022,12 @@  package body Sem_Ch12 is
                      and then Ekind (Root_Type (Act_T)) = E_Incomplete_Type)
          then
             --  If the formal is an incomplete type, the actual can be
-            --  incomplete as well.
+            --  incomplete as well, but if an actual incomplete type has
+            --  a full view, then we'll retrieve that.
 
-            if Ekind (A_Gen_T) = E_Incomplete_Type then
+            if Ekind (A_Gen_T) = E_Incomplete_Type
+              and then not Present (Full_View (Act_T))
+            then
                null;
 
             elsif Is_Class_Wide_Type (Act_T)
@@ -14032,6 +14035,7 @@  package body Sem_Ch12 is
             then
                Error_Msg_N ("premature use of incomplete type", Actual);
                Abandon_Instantiation (Actual);
+
             else
                Act_T := Full_View (Act_T);
                Set_Entity (Actual, Act_T);