diff mbox

[Ada] Unresolved discriminant selector of private overloaded prefix

Message ID 20110803101052.GA1767@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Aug. 3, 2011, 10:10 a.m. UTC
The compiler rejects a selected component naming a discriminant of a private
type when the prefix is overloaded. Prefixes of private types were not being
accounted for in analysis and resolution of an overloaded selected component.

The following test must compile quietly:

procedure Overloaded_Discrim_Selector is

   package Pkg is
      
      type Some_Rec is null record;
   
      function Func (I : Integer) return Some_Rec;

      type Another_Rec (Exists : Boolean := False) is private;      
      
      function Func (I : Integer) return Another_Rec;

   private
      
      type Another_Rec (Exists : Boolean := False) is null record;
      
   end Pkg;

   package body Pkg is
      
      function Func (I : Integer) return Some_Rec is
         S : Some_Rec;
      begin
         return S;
      end Func;         
      
      function Func (I : Integer) return Another_Rec is
         A : Another_Rec ;
      begin
         return A;
      end Func;
      
   end Pkg;
   
   use Pkg;

   B : Boolean := Func (123).Exists;

begin
   null;
end Overloaded_Discrim_Selector;

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

2011-08-03  Gary Dismukes  <dismukes@adacore.com>

	* sem_ch4.adb (Analyze_Overloaded_Selected_Component): Consider
	prefixes of private types along with records, since the selector may be
	a discriminant.
	* sem_res.adb (Resolve_Selected_Component): Consider prefixes of
	private types along with records, since the selector may be a
	discriminant.
diff mbox

Patch

Index: sem_res.adb
===================================================================
--- sem_res.adb	(revision 177258)
+++ sem_res.adb	(working copy)
@@ -8378,8 +8378,11 @@ 
                T := It.Typ;
             end if;
 
-            if Is_Record_Type (T) then
+            --  Locate selected component. For a private prefix the selector
+            --  can denote a discriminant.
 
+            if Is_Record_Type (T) or else Is_Private_Type (T) then
+
                --  The visible components of a class-wide type are those of
                --  the root type.
 
Index: sem_ch4.adb
===================================================================
--- sem_ch4.adb	(revision 177253)
+++ sem_ch4.adb	(working copy)
@@ -3127,8 +3127,11 @@ 
             T := It.Typ;
          end if;
 
-         if Is_Record_Type (T) then
+         --  Locate the component. For a private prefix the selector can denote
+         --  a discriminant.
 
+         if Is_Record_Type (T) or else Is_Private_Type (T) then
+
             --  If the prefix is a class-wide type, the visible components are
             --  those of the base type.