From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,27df3b4190d953db,start X-Google-Attributes: gid103376,public From: "Pat Rogers" Subject: statically compatible access discriminants in derivation Date: 1998/01/13 Message-ID: <69gucb$l9k$1@uuneo.neosoft.com>#1/1 X-Deja-AN: 315688865 X-MimeOLE: Produced By Microsoft MimeOLE V4.71.1712.3 Organization: NeoSoft, Inc. Newsgroups: comp.lang.ada Date: 1998-01-13T00:00:00+00:00 List-Id: Given a tagged type with an access discriminant designating a classwide type, and a child type derived from this parent type, is it possible to declare an access discriminant in the child type that is statically compatible with the parent's access discriminant, while having the child's access discriminant designate a classwide type further down in the parent's designated derivation class? (It's easier to see in the code below.) I want to constrain an access discriminant to designate only certain kinds of objects, i.e., those further down in the derivation class, so that I can take advantage of the additional information provided by the more specific view. I could use the inherited access discriminant without specifying one for the child type, and convert the inherited discriminant to the intended classwide type, but that seems rather weak in comparison. For example, consider the following declarations (ignore the names; I've chosen them for example purposes only): package device_if is -- device interface type object is abstract tagged null record; end device_if; with device_if; package unit_if is -- unit interface type object( board : access device_if.object'class ) is abstract tagged limited null record; end unit_if; Given a concrete instance of device_if.object, I want to use that classwide type in the access discriminant for a concrete instance of unit_if.object: with device_if; package device_instance is type object is new device_if.object with record x : integer; end record; end device_instance; with device_instance; with unit_if; package unit_instance is type object( board : access device_instance.object'class ) is new unit_if.object( board ) with null record; procedure foo( this : in out object ); end unit_instance; That way I can directly reference X within foo: package body unit_instance is procedure foo( this : in out object ) is begin this.board.x := 0; end foo; end unit_instance; As I read the RM, it seems that 3.7(15) requires them to statically match, and 4.9.1 says that they can not. Is there a way around this? As I mentioned, I could just inherit the discriminant 'board' designating device_if.object'class, and convert to device_instance.object'class, but would rather have it checked when the objects are declared. Any ideas?