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: border2.nntp.dca3.giganews.com!backlog4.nntp.dca3.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: A good program that not compile Date: Wed, 21 May 2014 16:58:43 +0100 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx05.eternal-september.org; posting-host="f944b7aa56b4100b8770465c51f11294"; logging-data="4575"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX184g1hIsXy8BTYqjJPChmalYfEppT150RM=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (darwin) Cancel-Lock: sha1:FxO/aQEtjzfiiSt3gmsS0hq73D8= sha1:Pq64HWjIo+latE2ajK48X4ICzgE= X-Original-Bytes: 2615 Xref: number.nntp.dca.giganews.com comp.lang.ada:186542 Date: 2014-05-21T16:58:43+01:00 List-Id: Victor Porton writes: > Simon Wright wrote: > >> Victor Porton writes: >> >>> The following does not compile. >> >> For very good reasons. >> >> Obtain_Handle(File_Handle) ought to be a function! >> It should take an in parameter, not in out! >> >> I take it your point is that you want to be able to declare >> >> function Obtain_Handle(Object: Abstract_Handle) return Integer >> is abstract; >> >> but I find that (with the latest compilers) this works: >> >> function Obtain_Handle(Object: Abstract_Handle) return Integer >> is (raise Program_Error); >> >> with the slight disadvantage of postponing failure to run time (which >> might happen anyway with your proposal). > > I have rewritten it with your suggestions. Now it does compile, but instead > as of to work as intended (Assigning 123 to the Handle) it raises > Program_Error. You have written (as before) overriding procedure Initialize(Object: in out Abstract_Handle) is begin Object.Handle := Obtain_Handle(Object); end; but I wrote overriding procedure Initialize(Object: in out Abstract_Handle) is begin Object.Handle := Obtain_Handle(Abstract_Handle'Class (Object)); -- ^^^^^^^^^^^^^^^^^^^^^^^ ^ -- use view conversion to get dispatching end; In your case, the call to Obtain_Handle is *not* dispatching. You need a classwide object (or access) to get dispatching; as you see, you can get this by a view conversion.