comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: accessibility check failed
Date: Sun, 29 Nov 2015 20:15:57 +0100
Date: 2015-11-29T20:15:57+01:00	[thread overview]
Message-ID: <1aslcq85i1z8f$.1rbttnghr6xqb$.dlg@40tude.net> (raw)
In-Reply-To: 3d45e3ed-16ca-4018-bf7b-62830acaca03@googlegroups.com

On Sun, 29 Nov 2015 10:03:25 -0800 (PST), Serge Robyns wrote:

> I'm facing a "mysterious" accessibility check failed error.

Nothing mysterious anonymous access + checks is an endless source of
problems in Ada.

> I'm having the following function:
> 
>    overriding function Get_Client
>      (Self        : not null access T_Data_Store;
>       Client_Name : in              T_Client_Name)
>       return T_Client'Class
>    is
>       Cursor : Client_Map.Cursor;
>    begin
>       Cursor := Self.Clients.Find (Client_Name);
>       if Cursor = Client_Map.No_Element then
>          return T_Client_DAO'(No_Client
>                                   with Store => Self);

Try Self.all'Unchecked_Access.

(Don't feel guilty about Unchecked_Access, all means are good in the holly
war against evil access checks... (:-))

> Researching the web for the accessibility check failed all refers to
> returning a reference to a local variable which is indeed disappearing on
> the execution of the return statement.  But in my case, I'm just storing
> the reference I did receive from the parent.

Yes, but how much up you pass that reference? The rules are too crude. Most
of alarms they generate are false alarms. I don't remember a case
accessibility check indeed helped to detect a bug.

> I did find a suggestion to replace anonymous access types to named ones
> but  that does not compile for the interface class for which the above
> function is an implementation.
 
It is a poor advice when you design a reusable component. Anonymous access
type is the most general type of reference imposing least constraint on the
clients. Thus it is the type to be used in all interfaces.

In the implementations a named access type is indeed the best and safest
choice.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

  parent reply	other threads:[~2015-11-29 19:15 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-29 18:03 accessibility check failed Serge Robyns
2015-11-29 18:37 ` Jeffrey R. Carter
2015-11-29 19:00   ` Serge Robyns
2015-11-29 22:32     ` Jeffrey R. Carter
2015-11-29 22:53       ` Serge Robyns
2015-11-30  2:04         ` Jeffrey R. Carter
2015-11-30 23:22         ` Randy Brukardt
2015-12-01  9:38           ` Serge Robyns
2015-11-29 19:15 ` Dmitry A. Kazakov [this message]
2015-11-29 22:40 ` Serge Robyns
2015-12-01 20:17 ` sbelmont700
  -- strict thread matches above, loose matches on Subject: below --
2014-08-11  2:12 Accessibility " hreba
2014-08-11  5:32 ` Jeffrey Carter
2014-08-11 16:45   ` hreba
2014-08-11 16:55     ` Jeffrey Carter
2014-08-12 11:57       ` hreba
2014-08-11 19:56 ` sbelmont700
2014-08-11 20:17   ` Jeffrey Carter
2014-08-11 20:28     ` sbelmont700
2014-08-11 21:14       ` Jeffrey Carter
replies disabled

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