diff mbox series

[Ada] Fix spurious error on instantiation with Text_IO name

Message ID 20220106171303.GA2921610@adacore.com
State New
Headers show
Series [Ada] Fix spurious error on instantiation with Text_IO name | expand

Commit Message

Pierre-Marie de Rodat Jan. 6, 2022, 5:13 p.m. UTC
This gets rid of a spurious error given by the compiler on the instantiation
of a generic package, when the instance happens to be an homonym of one of
the subpackages of Text_IO (Fixed_IO, Float_IO, etc) and when it is placed
in a context where Text_IO itself is also visible.

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

gcc/ada/

	* sem_ch8.adb (Analyze_Package_Renaming): Do not check for Text_IO
	special units when the name of the renaming is a generic instance,
	which is the case for package instantiations in the GNAT model.
diff mbox series

Patch

diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb
--- a/gcc/ada/sem_ch8.adb
+++ b/gcc/ada/sem_ch8.adb
@@ -1594,9 +1594,18 @@  package body Sem_Ch8 is
          return;
       end if;
 
-      --  Check for Text_IO special unit (we may be renaming a Text_IO child)
+      --  Check for Text_IO special units (we may be renaming a Text_IO child),
+      --  but make sure not to catch renamings generated for package instances
+      --  that have nothing to do with them but are nevertheless homonyms.
 
-      Check_Text_IO_Special_Unit (Name (N));
+      if Is_Entity_Name (Name (N))
+        and then Present (Entity (Name (N)))
+        and then Is_Generic_Instance (Entity (Name (N)))
+      then
+         null;
+      else
+         Check_Text_IO_Special_Unit (Name (N));
+      end if;
 
       if Current_Scope /= Standard_Standard then
          Set_Is_Pure (New_P, Is_Pure (Current_Scope));