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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.42.209.140 with SMTP id gg12mr8817869icb.26.1406770151623; Wed, 30 Jul 2014 18:29:11 -0700 (PDT) X-Received: by 10.182.131.166 with SMTP id on6mr32159obb.24.1406770151474; Wed, 30 Jul 2014 18:29:11 -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!h18no6756223igc.0!news-out.google.com!px9ni176igc.0!nntp.google.com!h18no10896863igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 30 Jul 2014 18:29:10 -0700 (PDT) In-Reply-To: <16a6846f-2964-438a-ab9b-2029075f7924@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=KSa2aQoAAACOxnC0usBJYX8NE3x3a1Xq NNTP-Posting-Host: 66.126.103.122 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: Subject: Re: Quick question regarding limited type return syntax From: Adam Beneschan Injection-Date: Thu, 31 Jul 2014 01:29:11 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:21363 Date: 2014-07-30T18:29:10-07:00 List-Id: On Wednesday, July 30, 2014 6:00:43 PM UTC-7, NiGHTS wrote: > On Wednesday, July 30, 2014 8:48:34 PM UTC-4, Shark8 wrote: >=20 > > On 30-Jul-14 17:51, NiGHTS wrote: >=20 > > > return Object (Connection_String'Access) do null; end return; > package body Test is > function Create(...) return Object is > ... > begin > return Object'(Connection_String'Access); > end; > ... > end Test; What you need to do is return an aggregate. And to return an aggregate, yo= u need to specify both fields--the Parameters discriminant and the Database= . This syntax: Object'(Connection_String'Access) is just wrong. It tells the compiler that the value is Connection_String'A= ccess, and asks the compiler to treat it as an Object. It can't do that, b= ecause Object isn't an access type. (This sort of syntax can be useful in = overloading cases, when the compiler can't determine the correct access typ= e without help.) If you said Object'(Parameters =3D> Connection_String'Access) you'd get an error that Database is missing. So you need Object'(Parameters =3D> Connection_String'Access, Database =3D> <>) or just (Parameters =3D> Connection_String'Access, Database =3D> <>) or =20 (Parameters =3D> Connection_String'Access, others =3D> <>) (It's OK for a function that returns a limited type to return an aggregate = like this.) The effect is that subcomponents of Database that have default initial valu= es will be initialized, and subcomponents that don't have default initial v= alues will be initialized to garbage (except where the language says otherw= ise). 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 t= o convince GNAT not to think you were accidentally leaving something initia= lized to garbage. =20 -- Adam