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,d6c75b0f89a0f085 X-Google-Attributes: gid103376,public From: Stephen Leake Subject: Re: What's wrong with this code? Date: 1999/04/21 Message-ID: #1/1 X-Deja-AN: 469191472 References: <7fi85m$sb3$1@nnrp1.dejanews.com> Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA Newsgroups: comp.lang.ada Date: 1999-04-21T00:00:00+00:00 List-Id: okellogg@my-dejanews.com writes: > package Alarm_Model is > > type Alarm is tagged limited private; > type Alarm_P is access all Alarm'Class; > > procedure Norm (This : access Alarm'Class); > > private > > type Alarm_State_Et is > (Snafu, Data, Proposal); > > type Alarm_State (My_Alarm : access Alarm) is > abstract tagged limited null record; > type Alarm_State_P is access all Alarm_State'Class; > > type Alarm_State_Pool_At is > array (Alarm_State_Et) of Alarm_State_P; > > procedure Enter (This : access Alarm_State); > > type Snafu_State is new Alarm_State with null record; > type Snafu_State_P is access all Snafu_State'Class; > > procedure Request_Data (This : access Snafu_State); > > type Data_State is new Alarm_State with null record; > type Data_State_P is access all Data_State'Class; > > type Proposal_State is new Alarm_State with null record; > type Proposal_State_P is access all Proposal_State'Class; > > protected type Alarm_Semaphore (My_Alarm : access Alarm) is > function Get return Alarm_State_P; > procedure Set (New_State : in Alarm_State_Et); > private > Current_State : Alarm_State_Et := Snafu; > ----------------------------- This is the workaround used > -- Alarm_State_Pool : Alarm_State_Pool_At := > -- (Snafu => new Snafu_State (My_Alarm), > -- Data => new Data_State (My_Alarm), > -- Proposal => new Proposal_State (My_Alarm)); > end Alarm_Semaphore; > > type Alarm is tagged limited > record > -- This compiles alright: > Semaphore : Alarm_Semaphore (Alarm'Access); > > -- But here, GNAT 3.11p says: > -- "Access" attribute cannot be applied to type > Alarm_State_Pool : Alarm_State_Pool_At := > (Snafu => new Snafu_State (Alarm'Access), > Data => new Data_State (Alarm'Access), > Proposal => new Proposal_State (Alarm'Access)); > > end record; > > end Alarm_Model; ObjectAda gives the error message (for Alarm_State_Pool): alarm_model.ads: Error: line 56 col 38 LRM:3.10.2(28), The accessibility level of the prefix to 'ACCESS shall not be statically deeper than that of the expected type of the allocator, Continuing (The LRM reference says the same thing :) Apparently using 'Access inside an allocator introduces an access layer? I don't see why it should in this case. In a function call, it might be a problem. And everything is at library level anyway. GNAT 3.11p gives the error: alarm_model.ads:56:55: "Access" attribute cannot be applied to type As others have pointed out, and as Semaphore demonstrates, it can too. So this is clearly a bad error message - send it in to ACT. I suspect both compilers are confused, not having encountered this construct before. As a work around, you could make Alarm a Controlled type, and create the Alarm_State_Pool objects in Initialize. -- Stephe