comp.lang.ada
 help / color / mirror / Atom feed
From: dmitry@elros.cbb-automation.de (Dmitry A. Kazakov)
Subject: GNAT error? [a generic child instance looses visibility]
Date: Mon, 18 Mar 2002 09:56:03 GMT
Date: 2002-03-18T09:56:03+00:00	[thread overview]
Message-ID: <3c95b5ad.4844359@News.CIS.DFN.DE> (raw)

The following code results in GNAT compilation error. I tried to
reduce the code amount as much as possible:
-----------------------------------------------------------------
package Obj is
   type X is tagged private;
private
   type X is tagged record
      Component : Integer; -- Visible for children only
   end record;
end Obj;
-----------------------------------------------------------------
generic
   type XX is new X with private;
package Obj.Child is
   type XX_Handle is tagged private;
   procedure Access_Internals (This : XX_Handle);
private
   type XX_Ptr is access all XX'Class;
   type XX_Handle is tagged record
      Ptr : XX_Ptr;
   end record;
end Obj.Child;
-----------------------------------------------------------------
package body Obj.Child is
   procedure Access_Internals (This : XX_Handle) is
   begin
      This.Ptr.Component := 0; -- Access the hidden component
   end Access_Internals;
end Obj.Child;
-----------------------------------------------------------------
with Obj.Child;

package Test is
   type Y_Handle is private;
   procedure Crash;
private
   type Y is new Obj.X with null record;
   type Y_Ptr is access all Y'Class;
   package Instantiation is new Obj.Child (Y);
   type Y_Handle is new Instantiation.XX_Handle with null record;
end Test;
-----------------------------------------------------------------
package body Test is
   procedure Crash is
      Var : Y_Handle;
   begin
      Access_Internals (Var);
   end Crash;
end Test;
-----------------------------------------------------------------
GNAT 3.14p  (20010503) Copyright 1992-2001 Free Software Foundation,
Inc.

Compiling: d:\home\dmitry\new\tests\new_i~eh\test.adb (source file
time stamp: 2002-03-18 09:44:16)

      1. package body Test is
      2.    procedure Crash is
      3.       Var : Y_Handle;
      4.    begin
      5.       Access_Internals (Var);
      6.    end Crash;
      7. end Test;

==============Error messages for source file:
d:\home\dmitry\new\tests\new_i~eh\test.ads
      9.    package Instantiation is new Obj.Child (Y);
           |
        >>> instantiation error at obj-child.adb:4
        >>> no selector "Component" for type "Y'Class" defined at line
7

 7 lines: 2 errors

It seems that during instantiation Obj.Child.Access_Internals looses
access to X.Component, no matter that it belongs to the child package.
Object Ada successfully compiles the example above. Also, GNAT's bug?

Regards,
Dmitry Kazakov



             reply	other threads:[~2002-03-18  9:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-18  9:56 Dmitry A. Kazakov [this message]
  -- strict thread matches above, loose matches on Subject: below --
2002-03-18 10:10 GNAT error? [a generic child instance looses visibility] Christoph Grein
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox