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.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: border1.nntp.dca3.giganews.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!69.16.185.11.MISMATCH!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!news.flashnewsgroups.com-b7.4zTQh5tI3A!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: "accessibility check failed" on Node References: Date: Thu, 27 Jun 2013 06:46:43 -0400 Message-ID: <85obarvnjg.fsf@stephe-leake.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (windows-nt) Cancel-Lock: sha1:KVAUFnYzEVQXycTnWc6DPVaj7U8= MIME-Version: 1.0 Content-Type: text/plain X-Complaints-To: abuse@flashnewsgroups.com Organization: FlashNewsgroups.com X-Trace: cc33451cc1817e25452d820846 X-Received-Bytes: 1945 X-Original-Bytes: 2133 Xref: number.nntp.dca.giganews.com comp.lang.ada:182111 Date: 2013-06-27T06:46:43-04:00 List-Id: Thomas Schmidt writes: > I'm new to Ada. Welcome! > Now what I don't understand: Why does "findNode1" work well while > "findNode2" raises PROGRAM_ERROR at the line indicated below? Accessibility refers to where an object is declared, relative to where its type is declared. > Given the following declarations: It's better if you post a complete compilable example, so we can compile it, and maybe fix the bug. > function findNode2 > (graph : DirectedGraph; > aNode : access Node'Class) > return Node_Class_Access is > > position : constant NodeSets.Cursor := > graph.nodes.Find (aNode.all'Access); -- <<< Raises > PROGRAM_ERROR with "accessibility check failed" First, a style note: since aNode is already an access, aNode.all'Access is just aNode. Is there some reason you wrote it this way? The accessiblity check applies to the object that aNode designates. If the type Node is declared at library level, but the object is at some lower level in a subprogram, then when that subprogram returns, the object will disappear, and the access value will become invalid. Ada forbids this. If you post a complete example, we can give more precise help. -- -- Stephe