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 X-Received: by 10.42.48.74 with SMTP id r10mr9173594icf.18.1406770704743; Wed, 30 Jul 2014 18:38:24 -0700 (PDT) X-Received: by 10.182.236.10 with SMTP id uq10mr48207obc.18.1406770704509; Wed, 30 Jul 2014 18:38:24 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!news.ripco.com!news.glorb.com!h18no10901301igc.0!news-out.google.com!px9ni176igc.0!nntp.google.com!h18no10901300igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 30 Jul 2014 18:38:23 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=73.179.102.101; posting-account=wEPvUgoAAABrLeiz_LRhQ3jeEhyfWVMH NNTP-Posting-Host: 73.179.102.101 References: <166aaec5-5e9c-40e0-9b07-9b9c7d5f7f33@googlegroups.com> <16a6846f-2964-438a-ab9b-2029075f7924@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <4e81ad37-f345-4b65-84a4-06fdc27fdaed@googlegroups.com> Subject: Re: Quick question regarding limited type return syntax From: NiGHTS Injection-Date: Thu, 31 Jul 2014 01:38:24 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:21364 Date: 2014-07-30T18:38:23-07:00 List-Id: On Wednesday, July 30, 2014 9:29:10 PM UTC-4, Adam Beneschan wrote: > On Wednesday, July 30, 2014 6:00:43 PM UTC-7, NiGHTS wrote: >=20 > > On Wednesday, July 30, 2014 8:48:34 PM UTC-4, Shark8 wrote: >=20 > >=20 >=20 > > > On 30-Jul-14 17:51, NiGHTS wrote: >=20 > >=20 >=20 > > > > return Object (Connection_String'Access) do null; end return; >=20 >=20 >=20 > > package body Test is >=20 > > function Create(...) return Object is >=20 > > ... >=20 > > begin >=20 > > return Object'(Connection_String'Access); >=20 > > end; >=20 > > ... >=20 > > end Test; >=20 >=20 >=20 > What you need to do is return an aggregate. And to return an aggregate, = you need to specify both fields--the Parameters discriminant and the Databa= se. This syntax: >=20 >=20 >=20 > Object'(Connection_String'Access) >=20 >=20 >=20 > is just wrong. It tells the compiler that the value is Connection_String= 'Access, and asks the compiler to treat it as an Object. It can't do that,= because Object isn't an access type. (This sort of syntax can be useful i= n overloading cases, when the compiler can't determine the correct access t= ype without help.) >=20 >=20 >=20 > If you said >=20 >=20 >=20 > Object'(Parameters =3D> Connection_String'Access) >=20 >=20 >=20 > you'd get an error that Database is missing. So you need >=20 >=20 >=20 > Object'(Parameters =3D> Connection_String'Access, Database =3D> <>) >=20 >=20 >=20 > or just >=20 >=20 >=20 > (Parameters =3D> Connection_String'Access, Database =3D> <>) >=20 >=20 >=20 > or =20 >=20 >=20 >=20 > (Parameters =3D> Connection_String'Access, others =3D> <>) >=20 >=20 >=20 > (It's OK for a function that returns a limited type to return an aggregat= e like this.) >=20 >=20 >=20 > The effect is that subcomponents of Database that have default initial va= lues will be initialized, and subcomponents that don't have default initial= values will be initialized to garbage (except where the language says othe= rwise). That's really the same as your original example was trying to do. = I guess that explicitly putting "others =3D> <>" in an aggregate is enough= to convince GNAT not to think you were accidentally leaving something init= ialized to garbage. =20 >=20 >=20 >=20 > -- Adam You're a good man Adam. Thank you for your very clear explanation. This wor= ked for me and I'm very pleased by how logical this ended up being. And thank you as well Shark8 for your help.